private async Task SetupCommands()
        {
            foreach (SocketApplicationCommand sac in await _client.GetGlobalApplicationCommandsAsync())
            {
                //await sac.DeleteAsync();
                if (sac.Name == "randomimage")
                {
                    Log(LogSeverity.Error, $"RandomImage command is already set up");
                    return;
                }
            }
            SlashCommandBuilder scb = new SlashCommandBuilder();

            scb.WithName("randomimage");
            scb.WithDescription("Post a random image");
            List <ChannelType> channelTypes = new List <ChannelType>();

            channelTypes.Add(ChannelType.Text);
            channelTypes.Add(ChannelType.DM);
            scb.AddOption("channel", ApplicationCommandOptionType.Channel, "Channel source", isRequired: true, channelTypes: channelTypes);
            try
            {
                Log(LogSeverity.Error, $"RandomImage command set up");
                await _client.CreateGlobalApplicationCommandAsync(scb.Build());
            }
            catch (Exception e)
            {
                Log(LogSeverity.Error, $"Error setting up slash command: {e.Message}");
            }
        }
Example #2
0
        private async Task Client_Ready()
        {
            return;

            var guild  = Client.GetGuild(000);
            var guild2 = Client.GetGuild(000);
            // Next, lets create our slash command builder. This is like the embed builder but for slash commands.
            var guildCommand = new SlashCommandBuilder();

            // Note: Names have to be all lowercase and match the regular expression ^[\w-]{3,32}$
            guildCommand.WithName("pixiv");

            // Descriptions can have a max length of 100.
            guildCommand.WithDescription("Pixiv command");
            guildCommand.AddOption(new SlashCommandOptionBuilder().WithName("id").WithDescription("Pixiv work").WithRequired(false).WithType(ApplicationCommandOptionType.Integer));

            try {
                var c1 = await guild.CreateApplicationCommandAsync(guildCommand.Build());

                var c2 = await guild2.CreateApplicationCommandAsync(guildCommand.Build());
            }
            catch (Exception exception) {
                Console.WriteLine(exception.Message + Environment.NewLine + exception.StackTrace);
            }
        }
Example #3
0
        public static async Task ResetCommandsAsync(DiscordSocketClient client)
        {
            await client.Rest.DeleteAllGlobalCommandsAsync();

            var statsCommand = new SlashCommandBuilder();
            statsCommand.WithName("stats");
            statsCommand.WithDescription("Prints the player statistics");
            statsCommand.AddOption("user", ApplicationCommandOptionType.User, "the user to print the stats", required: false);
            await client.Rest.CreateGlobalCommand(statsCommand.Build());

            var leaderboardCommand = new SlashCommandBuilder();
            leaderboardCommand.WithName("leaderboard");
            leaderboardCommand.WithDescription("Prints the leaderboard");
            await client.Rest.CreateGlobalCommand(leaderboardCommand.Build());

            var aboutCommand = new SlashCommandBuilder();
            aboutCommand.WithName("about");
            aboutCommand.WithDescription("Prints information about the bot and its author");
            await client.Rest.CreateGlobalCommand(aboutCommand.Build());

            var helpCommand = new SlashCommandBuilder();
            helpCommand.WithName("help");
            helpCommand.WithDescription("Prints all available commands in a category");
            helpCommand.AddOption("category", ApplicationCommandOptionType.String, "the category to view its commands", required: false);
            await client.Rest.CreateGlobalCommand(helpCommand.Build());
        }
        /// <summary>
        ///  Build the command and put it in a state in which we can use to define it to Discord.
        /// </summary>
        public SlashCommandCreationProperties BuildCommand()
        {
            var builder = new SlashCommandBuilder();

            builder.WithName(Name);
            builder.WithDescription(Description);
            builder.Options = new List <SlashCommandOptionBuilder>();

            foreach (var parameter in Parameters)
            {
                builder.AddOptions(parameter);
            }

            return(builder.Build());
        }
Example #5
0
        public SlashCommandCreationProperties BuildTopLevelCommandGroup()
        {
            SlashCommandBuilder builder = new SlashCommandBuilder();

            builder.WithName(commandGroupInfo.groupName);
            builder.WithDescription(commandGroupInfo.description);
            foreach (var command in Commands)
            {
                builder.AddOption(command.BuildSubCommand());
            }
            foreach (var commandGroup in commandGroups)
            {
                builder.AddOption(commandGroup.BuildNestedCommandGroup());
            }
            return(builder.Build());
        }
Example #6
0
            public async Task AddModule(string name, ulong guildID = 0)
            {
                if (!Privileg.CheckById(Context.User.Id, Privileg.owner))
                {
                    await Context.Channel.SendMessageAsync(embed : Classes.Embed.New(Context.Message.Author, Field.CreateFieldBuilder("warning", "You are not my god!"), Colors.warning));

                    Log.Warning($"command - admin add - user:{Context.User.Id} channel:{Context.Channel.Id} privileg to low");
                    return;
                }

                try
                {
                    List <SlashCommandBuilder> slashCommands = new List <SlashCommandBuilder>();

                    var command = new SlashCommandBuilder();

                    //help
                    {
                        command.WithName("help");
                        command.WithDescription("displays all bots commands");

                        command.AddOption("type", ApplicationCommandOptionType.String, "type of help", false, false, false, null, new ApplicationCommandOptionChoiceProperties {
                            Name = "data", Value = "data"
                        });

                        slashCommands.Add(command);
                    }

                    //get
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("get");
                        command.WithDescription("get various things");

                        var options = new List <ApplicationCommandOptionChoiceProperties>();
                        options.Add(new ApplicationCommandOptionChoiceProperties {
                            Name = "stats", Value = "stats"
                        });
                        options.Add(new ApplicationCommandOptionChoiceProperties {
                            Name = "leaderboard", Value = "leaderboard"
                        });

                        command.AddOption("what", ApplicationCommandOptionType.String, "what to get", true, false, false, null, options.ToArray());

                        slashCommands.Add(command);
                    }

                    //play
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("play");
                        command.WithDescription("play music from youtube");
                        command.AddOption("what", ApplicationCommandOptionType.String, "what to play", required: false);

                        slashCommands.Add(command);
                    }

                    //stop
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("stop");
                        command.WithDescription("stop music");

                        slashCommands.Add(command);
                    }

                    //skip
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("skip");
                        command.WithDescription("skip music track");

                        slashCommands.Add(command);
                    }

                    //leave
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("leave");
                        command.WithDescription("leave the connected voice channel");

                        slashCommands.Add(command);
                    }

                    //shuffle
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("shuffle");
                        command.WithDescription("shuffle music queue");

                        slashCommands.Add(command);
                    }

                    //queue
                    {
                        command = new SlashCommandBuilder();
                        command.WithName("queue");
                        command.WithDescription("list the 5 next music tracks");

                        slashCommands.Add(command);
                    }

                    foreach (var slashCommand in slashCommands)
                    {
                        if (guildID != 0)
                        {
                            if (slashCommand.Name == name)
                            {
                                await Program.Client.Rest.CreateGuildCommand(slashCommand.Build(), guildID);
                            }
                        }
                        else
                        {
                            if (slashCommand.Name == name)
                            {
                                await Program.Client.Rest.CreateGlobalCommand(slashCommand.Build());
                            }
                        }
                    }

                    await Context.Message.ReplyAsync(embed : Classes.Embed.New(Context.Message.Author, Field.CreateFieldBuilder("info", "done!"), Colors.information));
                }
                catch (ApplicationCommandException ex)
                {
                    var json = JsonConvert.SerializeObject(ex.Error, Formatting.Indented);
                    await Context.Message.ReplyAsync(embed : Classes.Embed.New(Context.Message.Author, Field.CreateFieldBuilder("error", json), Colors.error));
                }
                catch (Exception ex)
                {
                    Log.Error($"command - !admin get - user:{Context.Message.Author.Id} channel:{Context.Channel.Id} error:{ex.Message}");
                }
            }