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); } }
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}"); } }
public override ApplicationCommandProperties Build() { var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions); SlashCommandOptionBuilder optionBuilder = new SlashCommandOptionBuilder() { Name = "configure", Description = "Gets all match history for a team or teams.", Type = ApplicationCommandOptionType.SubCommand }; optionBuilder.AddOption( name: "configuration", type: ApplicationCommandOptionType.String, description: "The full JSON configuration for the CEA bot.", isRequired: true); builder.AddOption(optionBuilder); return(builder.Build()); }
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()); }
public CommandManager(ulong?debugGuildId) { _debugGuildId = debugGuildId; _commands = new() { #region Communication Module { "info", new() { Callback = CommunicationModule.InfoAsync, SlashCommand = new SlashCommandBuilder() { Name = "info", Description = "Get information about the bot" }.Build() } }, { "help", new() { Callback = CommunicationModule.HelpAsync, SlashCommand = new SlashCommandBuilder() { Name = "help", Description = "Get the help" }.Build() } },
public override ApplicationCommandProperties Build() { var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions); return(builder.Build()); }
public override ApplicationCommandProperties Build() { var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions); builder.AddOption( name: "number_only", type: ApplicationCommandOptionType.Boolean, description: "Outputs only the version number"); return(builder.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()); }
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()); }
public override SlashCommandProperties Build() { var addCmd = new SlashCommandOptionBuilder() { Name = "add", Description = "Add your RL tracker for the next season of CEA!", Type = ApplicationCommandOptionType.SubCommand }; addCmd.AddOption("platform", ApplicationCommandOptionType.String, "Platorm you play on", required: true, choices: new ApplicationCommandOptionChoiceProperties[] { new ApplicationCommandOptionChoiceProperties() { Name = "epic", Value = "Epic" }, new ApplicationCommandOptionChoiceProperties() { Name = "steam", Value = "Steam" }, new ApplicationCommandOptionChoiceProperties() { Name = "playstation", Value = "Playstation" }, new ApplicationCommandOptionChoiceProperties() { Name = "xbox", Value = "Xbox" }, new ApplicationCommandOptionChoiceProperties() { Name = "tracker", Value = "Tracker" } }); addCmd.AddOption("id", ApplicationCommandOptionType.String, "For steam use your id, others use username, tracker post full tracker", required: true); var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions) .AddOption(addCmd); return(builder.Build()); }
public override ApplicationCommandProperties Build() { var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions); foreach (ICeaSubCommand subCommand in subCommands.Values) { SlashCommandOptionBuilder optionBuilder = subCommand.OptionBuilder; SlashCommandUtils.AddCommonOptionProperties(optionBuilder, subCommand.SupportedOptions); builder.AddOption(optionBuilder); } return(builder.Build()); }
public static SlashCommandProperties ToApplicationCommandProps(this SlashCommandInfo commandInfo) { var props = new SlashCommandBuilder() { Name = commandInfo.Name, Description = commandInfo.Description, IsDefaultPermission = commandInfo.DefaultPermission, }.Build(); if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) { throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters"); } props.Options = commandInfo.Parameters.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional <List <ApplicationCommandOptionProperties> > .Unspecified; return(props); }
public static SlashCommandProperties ToApplicationCommandProps(this SlashCommandInfo commandInfo) { var props = new SlashCommandBuilder() { Name = commandInfo.Name, Description = commandInfo.Description, IsDMEnabled = commandInfo.IsEnabledInDm, DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), }.Build(); if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) { throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters"); } props.Options = commandInfo.FlattenedParameters.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional <List <ApplicationCommandOptionProperties> > .Unspecified; return(props); }
public override SlashCommandProperties Build() { // TODO: Add directly to a team var addCmd = new SlashCommandOptionBuilder() { Name = "adminadd", Description = "Add a user to the recruiting board", Type = ApplicationCommandOptionType.SubCommand }; addCmd.AddOption("username", ApplicationCommandOptionType.User, "Username of user to move", isRequired: true); addCmd.AddOption("platform", ApplicationCommandOptionType.String, "Platorm you play on", isRequired: true, choices: new ApplicationCommandOptionChoiceProperties[] { new ApplicationCommandOptionChoiceProperties() { Name = "epic", Value = "Epic" }, new ApplicationCommandOptionChoiceProperties() { Name = "steam", Value = "Steam" }, new ApplicationCommandOptionChoiceProperties() { Name = "playstation", Value = "Playstation" }, new ApplicationCommandOptionChoiceProperties() { Name = "xbox", Value = "Xbox" }, new ApplicationCommandOptionChoiceProperties() { Name = "tracker", Value = "Tracker" } }); addCmd.AddOption("id", ApplicationCommandOptionType.String, "For steam use your id, others use username, tracker post full tracker", isRequired: true); addCmd.AddOption("team", ApplicationCommandOptionType.String, "Team to add this user to. If left blank, defaults to Free Agents", isRequired: false); var moveCmd = new SlashCommandOptionBuilder() { Name = "move", Description = "Move a tracked user to a team.", Type = ApplicationCommandOptionType.SubCommand }; moveCmd.AddOption("username", ApplicationCommandOptionType.User, "Username of user to move", isRequired: true); moveCmd.AddOption("team", ApplicationCommandOptionType.String, "Team to move user to", isRequired: true); moveCmd.AddOption("captain", ApplicationCommandOptionType.Boolean, "Is this user the captain of the team?", isRequired: false); var removeCmd = new SlashCommandOptionBuilder() { Name = "remove", Description = "Remove a tracked user.", Type = ApplicationCommandOptionType.SubCommand }; removeCmd.AddOption("username", ApplicationCommandOptionType.User, "Username of user to remove", isRequired: true); var deleteTeamCmd = new SlashCommandOptionBuilder() { Name = "deleteteam", Description = "Remove team.", Type = ApplicationCommandOptionType.SubCommand }; deleteTeamCmd.AddOption("team", ApplicationCommandOptionType.String, "Team to remove", isRequired: true); var lookingForPlayersCmd = new SlashCommandOptionBuilder() { Name = "lookingforplayers", Description = "Mark your team as looking for players or not.", Type = ApplicationCommandOptionType.SubCommand }; lookingForPlayersCmd.AddOption("team", ApplicationCommandOptionType.String, "Team to mark as looking for players", isRequired: true); lookingForPlayersCmd.AddOption("looking", ApplicationCommandOptionType.Boolean, "Are you looking for new players", isRequired: true); var builder = new SlashCommandBuilder() .WithName(this.Name) .WithDescription(this.Description) .WithDefaultPermission(this.DefaultPermissions) .AddOptions(addCmd, moveCmd, removeCmd, deleteTeamCmd, lookingForPlayersCmd); return(builder.Build()); }
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}"); } }