forked from BrammyS/Discord-Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BrammyS#44 - Creating your own slash commands!: invite command
- Loading branch information
1 parent
616f8a6
commit 1380f13
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Bot.Discord.Components; | ||
using Color_Chan.Discord.Commands.Attributes; | ||
using Color_Chan.Discord.Commands.Attributes.ProvidedRequirements; | ||
using Color_Chan.Discord.Commands.MessageBuilders; | ||
using Color_Chan.Discord.Commands.Modules; | ||
using Color_Chan.Discord.Core.Common.Models.Embed; | ||
using Color_Chan.Discord.Core.Common.Models.Interaction; | ||
using Color_Chan.Discord.Core.Results; | ||
|
||
namespace Bot.Discord.Commands; | ||
|
||
/// <summary> | ||
/// The command module for inviting the bot to other Discord's servers. | ||
/// </summary> | ||
[UserRateLimit(5, 10)] // Sets the rate lcimit for this command module to 5 requests per 10 seconds per user. | ||
public class InviteCommands : SlashCommandModule | ||
{ | ||
public const string InviteCommandName = "invite"; | ||
public const string InviteCommandDesc = "Invite the bot somewhere else!"; | ||
|
||
|
||
/// <summary> | ||
/// An invitation command where the bot will reply back with a link to be added to other servers. | ||
/// </summary> | ||
/// <returns> | ||
/// An embedded response with the provided message. | ||
/// </returns> | ||
[SlashCommand(InviteCommandName, InviteCommandDesc)] | ||
public Task<Result<IDiscordInteractionResponse>> InviteAsync() | ||
{ | ||
// Build the embedded response. | ||
var inviteResponse = new InteractionResponseBuilder() | ||
.WithEmbed(InviteMeEmbed) | ||
.WithComponent(InviteButtons.InviteMe) | ||
.Build(); | ||
|
||
// Return the response to Discord. | ||
return Task.FromResult(FromSuccess(inviteResponse)); | ||
} | ||
|
||
public static readonly IDiscordEmbed InviteMeEmbed = | ||
new DiscordEmbedBuilder() | ||
.WithTitle("Invite me") | ||
.WithDescription("I need more friends, add me to other Discord servers!") | ||
.WithColor(Constants.Colors.Successful) | ||
.WithTimeStamp() | ||
.Build(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Color_Chan.Discord.Commands.MessageBuilders; | ||
using Color_Chan.Discord.Core.Common.API.DataModels; | ||
using Color_Chan.Discord.Core.Common.Models; | ||
|
||
namespace Bot.Discord.Components; | ||
|
||
public static class InviteButtons | ||
{ | ||
public static readonly IDiscordComponent InviteMe = | ||
new ActionRowComponentBuilder() | ||
.WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands") | ||
.Build(); | ||
} |