I started writing a Discord bot, but I was already running into a problem. To a large extent, I simply wrote what he wrote with some minor changes that should not greatly affect the program. I have 2 classes, the main class, which simply receives a token for the bot, and then creates the bot with
MyBot bot = MyBot(token)
Here is MyBot.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
namespace Coding_Bot
{
class MyBot
{
DiscordClient discord;
String botToken;
public MyBot(String tempToken)
{
botToken = tempToken;
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
Console.WriteLine("[BOT] Connecting...");
discord.ExecuteAndWait(async () =>
{
await discord.Connect(botToken, TokenType.Bot);
});
discord.UsingCommands(x =>
{
x.PrefixChar = '.';
x.AllowMentionPrefix = true;
});
var commands = discord.GetService<CommandService>();
commands.CreateCommand("info").Do(async (e) =>
{
Console.WriteLine("!info executed");
await e.Channel.SendMessage("Coding Bot");
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine("[BOT] " + e.Message);
}
}
}
It connects and Bot starts online. This is the output in my console:
[BOT] Connecting...
[BOT] Connected
[BOT] GUILD_AVAILABLE: BotTestServer
When I now enter .info in #general, nothing happens. Nothing in the console and nothing in #general. I already reviewed this one , but this did not solve my problem.
EDIT: , CommandHandler, . , .