Issue with Command Recognition in Separate Module Class
I’m working on a Discord bot using Discord.NET 1.0 and C#. I can get commands to work when they’re in my main module, but when I try to create a separate class for organizing commands, the bot returns “Unknown command” errors.
Working Main Module
using Discord.Commands;
using System.Threading.Tasks;
namespace BotApp.Commands.Main
{
public class MainCommands : ModuleBase
{
[Command("info")]
[Summary("Shows bot information")]
public async Task ShowInfo()
{
var app = await Context.Client.GetApplicationInfoAsync();
await ReplyAsync($"Bot invite link: <https://discord.com/oauth2/authorize?client_id={app.Id}&scope=bot>");
}
[Command("exit")]
[Summary("Makes the bot leave the server")]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task ExitServer()
{
if (Context.Guild == null)
{
await ReplyAsync("This only works in servers.");
return;
}
await ReplyAsync("Goodbye!");
await Context.Guild.LeaveAsync();
}
}
}
Separate Module That Doesn’t Work
using Discord.Commands;
using System.Threading.Tasks;
namespace BotApp.Commands.Main
{
class TextCommands : ModuleBase
{
[Command("repeat")]
[Alias("copy")]
[Summary("Repeats your message")]
public async Task RepeatMessage([Remainder] string message)
{
await ReplyAsync(message);
}
}
}
The second class gives “Unknown command” when I try using the repeat command. Both classes are in the same namespace and follow the same pattern. What am I missing to make the separate module work properly?