Im trying to make a bot that would create some roles when you use a slash command. Also i have to custom classes that would contain role
s name and ID. However, when Im trying to create roles, bot just sends a message that application doesn
t respond and, probably, creates only 1 role.
Code:
{
var file = new FileInfo(@"C:\Users\mishk\Desktop\Bot\BotRaphael\BotRaphael\Races.json");
if (file.Length == 0)
{
Race[] races = new Race[Constants.races.Length];
DnDClass[] dnDClasses = new DnDClass[Constants.classes.Length];
for (int i = 0; i < Constants.races.Length; i++)
{
DiscordRole role = await ctx.Guild.CreateRoleAsync(Constants.races[i], null, DiscordColor.Magenta);
races[i].raceName = Constants.races[i];
races[i].raceID = role.Id;
}
for (int i = 0; i < Constants.classes.Length; i++)
{
DiscordRole role = await ctx.Guild.CreateRoleAsync(Constants.classes[i], null, DiscordColor.Gold);
dnDClasses[i].className = Constants.classes[i];
dnDClasses[i].classID = role.Id;
}
I suppose problem may be in for-loops, but I tried to remove them and create just one role and it seems not to always work out. If I use arrays of custom classes itll give the same error. Not sure what I
m supposed to look into, but it seems that bot merely cant handle to process a couple of arrays.
In the code sample you provided your bot does not return anything to the user who issued the command, meaning it literally didn't respond which is what leads to the error message in Discord. Your bot should always respond to the user who issued the command, so Discord will always present an error message if it doesn't.
If your commands are slash commands respond to the user like this:
if your commands are standard commands respond like this:
where
"msg"
should be replaced with whatever your response is.In terms of creating multiple roles with a single command that's not something I have personally tried, but what you might need to do is create a normal command method to issue a single new role and then another command that acts as a wrapper for it to process the single new role multiple times. Watch out for your rate limit though.