Command sends Embed message in a different server rather than where it was called from
See original GitHub issueSummary
I’m hosting my bot on a VPS since on every website I searched there are no services that host C# discord bots. Anyways, whenever I use my help command in my bot, whenever I press a button it doesn’t send the message in the channel where the command was called and instead sends it to my Test server which is weird.
Details
Basically, I have a help command which consists of some buttons for each section of my command list like Utility/Fun Commands/Games. When I was testing this bot, everything was working well but when I started up the bot on my VPS, and then used the same help command and press a button, it just doesn’t work properly anymore. The first half of the code executes perfectly but it doesn’t send the embedded message of the command list to the right channel. Instead, it sends it to my Test server which is so weird.
This is my Help command Code:
[Command("help")]
public async Task HelpMenu(CommandContext ctx)
{
var mainMenuBuilder = new DiscordMessageBuilder()
.AddEmbed(
new DiscordEmbedBuilder()
.WithTitle("Cooler Is Gay Bot | Made by Samuel J \n ©SamuelJesuthas \n\n Help Menu")
.WithDescription("This is a multi-utility bot which just features random stuff \n Click on a category to view its list of commands \n The prefix is '>' ")
)
.AddComponents(new DiscordComponent[]
{
new DiscordButtonComponent(ButtonStyle.Primary, "calculatorFunction", "Calculator"),
new DiscordButtonComponent(ButtonStyle.Primary, "funFunction", "Fun Commands"),
new DiscordButtonComponent(ButtonStyle.Primary, "gamesFunction", "Games"),
new DiscordButtonComponent(ButtonStyle.Primary, "toolsFunction", "Tools"),
new DiscordButtonComponent(ButtonStyle.Danger, "exitFunction", "Exit")
}
);
await ctx.Channel.SendMessageAsync(mainMenuBuilder);
ctx.Client.ComponentInteractionCreated += async (a, b) =>
{
if (b.Interaction.Data.CustomId == "calculatorFunction")
{
await b.Interaction.CreateResponseAsync(
InteractionResponseType.UpdateMessage,
new DiscordInteractionResponseBuilder()
.WithContent("Opening Calculator Commands")
);
var basicFunctionMessage = new DiscordMessageBuilder()
.AddEmbed(
new DiscordEmbedBuilder()
.WithTitle("Basic Calculator Functions")
.WithDescription(">add -> Add 2 numbers together | E.g: >add 2 2, returns 4 \n\n " +
">subtract -> Subtract 2 numbers together | E.g: >subtract 4 3, returns 1 \n\n " +
">multiply -> Multiply 2 numbers together | E.g: >multiply 6 4, returns 24 \n\n " +
">divide -> Divide 2 numbers together | E.g: >divide 5 2, returns 2.5 \n\n " +
">circlearea -> Gives you the area of a circle with any radius | E.g: >circlearea 2, returns 12.57")
);
await ctx.Channel.SendMessageAsync(basicFunctionMessage);
}
if (b.Interaction.Data.CustomId == "funFunction")
{
await b.Interaction.CreateResponseAsync(
InteractionResponseType.UpdateMessage,
new DiscordInteractionResponseBuilder()
.WithContent("Opening Fun Commands")
);
var funFunctionMessage = new DiscordMessageBuilder()
.AddEmbed(
new DiscordEmbedBuilder()
.WithTitle("Fun Commands")
.WithDescription(">ducky -> Tell Ducky to shut the fuck up \n\n" +
">tory -> Slander the torys \n\n" +
">delet -> Prove that everything is mid with this one command \n\n " +
">question -> Answer a random question about cooler \n\n " +
">dialogue -> The bot will send you a DM, type anything random to send it back to the channel where you used the command \n\n" +
">watchyourtone -> Tell someone to watch their tone | Syntax: >watchyourtone @User \n\n" +
">fortune -> See if your fate is lucky or will it be hell")
);
await ctx.Channel.SendMessageAsync(funFunctionMessage);
}
if (b.Interaction.Data.CustomId == "gamesFunction")
{
await b.Interaction.CreateResponseAsync(
InteractionResponseType.UpdateMessage,
new DiscordInteractionResponseBuilder()
.WithContent("Opening Game Commands")
);
var gamesFunctionMessage = new DiscordMessageBuilder()
.AddEmbed(
new DiscordEmbedBuilder()
.WithTitle("Game Commands")
.WithDescription(">cardgame -> Play a simple card game. Press the button to draw a card \n " +
"If your card is higher than what the bot draws, You Win \n\n" +
">lottery -> Play the lottery, pick 5 numbers from 1-50 and test your luck | " +
"Syntax: >lottery num1 num2 num3 num4 num5 \n\n " +
">lottorules -> Displays information on how to play the '>lottery' command")
);
await ctx.Channel.SendMessageAsync(gamesFunctionMessage);
}
if (b.Interaction.Data.CustomId == "toolsFunction")
{
await b.Interaction.CreateResponseAsync(
InteractionResponseType.UpdateMessage,
new DiscordInteractionResponseBuilder()
.WithContent("Opening Tools Commands")
);
var toolsFunctionMessage = new DiscordMessageBuilder()
.AddEmbed(
new DiscordEmbedBuilder()
.WithTitle("Tools Commands")
.WithDescription(">timestamp -> After using this command, the next message you send the bot will return the exact time and date you sent it \n\n " +
">status -> Only Sam and Delet can use this command. Sets the 'Playing' status of the bot to any text. There cannot be any spaces \n\n " +
">invite -> Generates an invite link for the bot, use it to add it to other servers of your choice")
);
await ctx.Channel.SendMessageAsync(toolsFunctionMessage);
}
if (b.Interaction.Data.CustomId == "exitFunction")
{
await b.Interaction.CreateResponseAsync(
InteractionResponseType.UpdateMessage,
new DiscordInteractionResponseBuilder()
.WithContent("You have exit the menu. Type in >help to use it again")
);
}
};
}
When this issue happened I got this error in the console:
From my experience, it looks like a timing issue but honestly the server is running well, there’s no errors with it, its just no executing the embed message commands to show the list of commands. It just executes the “InteractionResponseType.UpdateMessage” section of the command and sends the embed in my Test server
Calling the command on my public server:
After pressing a button:
Embed appears in a different server (My Test one):
Steps to reproduce
- You can use this exact same code in a Command class as you would normally do and try running the command in a VPS to see if you also have the same issue
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I’ll be sure to add a button example. Thank you for posting this for others to see!
Ok, I finally managed to figure it out. With the limited help/articles/documentation being an issue I will post a solution here for anyone else to use since there are no YouTube videos, Stack Overflow issues, Documentation that addresses this issue directly. I know its all down to skill but we all started from nothing so hopefully this will help anyone in the future
Example Code for making buttons
In your Bot.cs file register a ComponentInteractionCreated after creating your client and generate a method for it (VS 2022 users just press TAB after doing +=)
After generating your method, you can pass in your CustomIDs and execute different code based on what button it is
It might seem weird to newbies that you have to manage the Buttons from the Bot.cs file rather than in the command class but I now understand why registering the eventhandler in the command is a bad thing