Created
May 15, 2022 14:43
-
-
Save HugoVG/6977c7336f0426ac486cbe5d42af8ef6 to your computer and use it in GitHub Desktop.
Dsharpplus SlashCommands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if you want to make a group command with like a /example function you have to make a slash group | |
[SlashCommandGroup("example", "for example purposes")] | |
public class exampleCommands : ApplicationCommandModule | |
{ | |
//ONLY FOR BAKABOT DEV | |
public Configuration configuration { get; set; } //reference this for using configuration singleton | |
// | |
//Adding SlashCommands | |
[SlashCommand("function", "function you want to add")] //will activate on /example function | |
public async Task functiontobecalled(InteractionContext ctx) //this is for no Parameters | |
{ | |
//this will make the bot go into "thinking" mode | |
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource); | |
//Your own logic here | |
//to reply | |
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("function called")); | |
} | |
//Adding SlashCommands with parameters | |
[SlashCommand("functionTwo", "function you want to add now with parameters")] //will activate on /example function | |
public async Task functiontobecalled(InteractionContext ctx, | |
[Option("user", "User to be called")] DiscordUser user) //Option is used to give the user the input value, to make it optional add an = something | |
{ | |
//this will make the bot go into "thinking" mode | |
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource); | |
//Your own logic here | |
//to reply | |
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($ "{user.Mention}, function called")); | |
} | |
//Adding SlashCommands with dropdownMenu | |
[SlashCommand("functionDrop", "function you want to add now with Dropdown")] //will activate on /example function | |
public async Task functiontobedroppedown(InteractionContext ctx, | |
[Option("modrank", "just for display")] Modrank Rank = Modrank.User) //this will give a dropdown with the enum down below | |
{ | |
//this will make the bot go into "thinking" mode | |
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource); | |
//Your own logic here | |
//to reply | |
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($ "{Rank}")); | |
} | |
public enum Modrank : int | |
{ | |
[ChoiceName("User")] User = 1, //Choice name is what the user sees, you only see Modrank.User for example | |
[ChoiceName("Moderator")] Moderator = 2, | |
[ChoiceName("Developer")] Dev = 3, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Registering commands | |
//... Program.cs crap here | |
var slash = await discord.UseSlashCommandsAsync(); | |
slash.RegisterCommands<exampleCommands>(); | |
//...Rest of Program.cs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment