I wrote a conversation. It is developed using C #. My list of commands is populated, the value of the command gets this list. But the command does not execute the code when it is called.
My char prefix is '!' followed by a team. My base class looks like this:
public class Bot
{
string token = "#######################";
CommandService command;
EventController eventController = new EventController();
CommandController commandController = new CommandController();
public Bot()
{
var client = new DiscordClient();
client = new DiscordClient(input =>
{
input.LogLevel = LogSeverity.Info;
input.LogHandler = Log;
});
client.UsingCommands(input =>
{
input.PrefixChar = '!';
input.AllowMentionPrefix = true;
});
eventController.HandleEvents(client);
command = client.GetService<CommandService>();
commandController.HandleCommands(command, client);
client.ExecuteAndWait(async() =>
{
while (true)
{
await client.Connect(token, TokenType.Bot);
break;
}
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
I divided the code into two classes: eventController and commandController. The command controller is relevant.
My class of commands is as follows:
private List<Tuple<string, string, string>> commandList = new List<Tuple<string, string, string>>();
public void HandleCommands(CommandService command, DiscordClient client)
{
FillCommandList();
foreach (Tuple<string, string, string> tuple in commandList)
{
command.CreateCommand('!' + tuple.Item1).Do(async (e) =>
{
await e.Channel.SendMessage(tuple.Item2);
});
}
}
private void Add(string commandName, string textToReturn, string commandDescription)
{
commandList.Add(new Tuple<string, string, string>(commandName, textToReturn, commandDescription));
}
private void FillCommandList()
{
Add("test0", "success0", "info0");
Add("test1", "success1", "info1");
Add("test2", "success2", "info2");
Add("test3", "success3", "info3");
Add("help", UseHelp(), "List all Commands");
}
private string UseHelp()
{
string commandItems = "";
foreach (Tuple<string, string, string> tuple in commandList)
{
commandItems += "- !" + tuple.Item1 + " - " + tuple.Item3 + "\r\n";
}
return commandItems;
}
Therefore, when I call a command like "test0" or "UseHelp ()", the command gets the string contents. All 5 teams are listed to the bot. But when I use the command in Discord, Bot is not responding.
It is connected and filled with "command" data ...