Skip to content

Commit

Permalink
BrammyS#44 - Creating your own slash commands!: invite command
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgfedericotomasi committed Oct 16, 2022
1 parent 616f8a6 commit 1380f13
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Bot.Discord/Commands/InviteCommands.cs
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();
}
13 changes: 13 additions & 0 deletions src/Bot.Discord/Components/InviteButtons.cs
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();
}

0 comments on commit 1380f13

Please sign in to comment.