* initial * Interaction glossary entry * Sharded Interaction sample * Renames into solution * Debugging samples * Modify target location for webhookclient * Finalizing docs work, resolving docfx errors. * Adding threaduser to user chart * Add branch info to readme. * Edits to user chart * Resolve format for glossary entries * Patch sln target * Issue with file naming fixed * Patch 1/x for builds * Appending suggestions
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using Discord;
|
|
using Discord.Interactions;
|
|
using Discord.WebSocket;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace InteractionFramework.Modules
|
|
{
|
|
// A transient module for executing commands. This module will NOT keep any information after the command is executed.
|
|
internal class MessageCommandModule : InteractionModuleBase<SocketInteractionContext<SocketMessageCommand>>
|
|
{
|
|
// Pins a message in the channel it is in.
|
|
[MessageCommand("pin")]
|
|
public async Task PinMessageAsync(IMessage message)
|
|
{
|
|
// make a safety cast to check if the message is ISystem- or IUserMessage
|
|
if (message is not IUserMessage userMessage)
|
|
await RespondAsync(text: ":x: You cant pin system messages!");
|
|
|
|
// if the pins in this channel are equal to or above 50, no more messages can be pinned.
|
|
else if ((await Context.Channel.GetPinnedMessagesAsync()).Count >= 50)
|
|
await RespondAsync(text: ":x: You cant pin any more messages, the max has already been reached in this channel!");
|
|
|
|
else
|
|
{
|
|
await userMessage.PinAsync();
|
|
await RespondAsync(":white_check_mark: Successfully pinned message!");
|
|
}
|
|
}
|
|
}
|
|
}
|