added example for plugins
This commit is contained in:
@@ -26,7 +26,7 @@ func ready(e *events.Ready) {
|
|||||||
removeOldCommandFromAllGuilds(e.Client())
|
removeOldCommandFromAllGuilds(e.Client())
|
||||||
err := loadPlugins("plugins/", e)
|
err := loadPlugins("plugins/", e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
var existingCommandNames []string
|
var existingCommandNames []string
|
||||||
existingCommands, err := e.Client().Rest().GetGlobalCommands(e.Client().ApplicationID(), false)
|
existingCommands, err := e.Client().Rest().GetGlobalCommands(e.Client().ApplicationID(), false)
|
||||||
@@ -106,10 +106,8 @@ func loadPlugins(directory string, e *events.Ready) error {
|
|||||||
}
|
}
|
||||||
if plugin.Register != nil {
|
if plugin.Register != nil {
|
||||||
err = plugin.Register(e)
|
err = plugin.Register(e)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
logrus.Infof("Successfully appended plugin %s for registration", plugin.Name)
|
logrus.Errorf("Error running plugin register %s function: %v", plugin.Name, err)
|
||||||
} else {
|
|
||||||
logrus.Errorf("Error registering plugin %s commands: %v", plugin.Name, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,11 +3,20 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/disgoorg/disgo/discord"
|
"github.com/disgoorg/disgo/discord"
|
||||||
"github.com/disgoorg/disgo/events"
|
"github.com/disgoorg/disgo/events"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/vaporvee/acecore/struct_cmd"
|
"github.com/vaporvee/acecore/struct_cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Plugin = &struct_cmd.Plugin{
|
var Plugin = &struct_cmd.Plugin{
|
||||||
Name: "testplugin",
|
Name: "testplugin",
|
||||||
|
Register: func(e *events.Ready) error {
|
||||||
|
app, err := e.Client().Rest().GetCurrentApplication()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logrus.Infof("%s has a working plugin called \"testplugin\"", app.Bot.Username)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Commands: []struct_cmd.Command{
|
Commands: []struct_cmd.Command{
|
||||||
{
|
{
|
||||||
Definition: discord.SlashCommandCreate{
|
Definition: discord.SlashCommandCreate{
|
Reference in New Issue
Block a user