Discord Bot [C#] 不执行命令

Discord Bot [C#] does not execute the Command

我开始编写一个 Discord 机器人,但我已经 运行 解决了一个问题。我几乎只是写了 he 写的一些小改动,这些改动不会对程序造成太大影响。我有 2 个 类,Main class,它只是获取机器人的令牌,然后使用

创建机器人
MyBot bot = MyBot(token)

这里是 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);
        }
    }
}

它确实连接了,并且 Bot 确实上线了。这是我的控制台中的输出:

[BOT] Connecting...
[BOT] Connected
[BOT] GUILD_AVAILABLE: BotTestServer

当我现在在#general 中输入.info 时,没有任何反应。控制台中没有任何内容,#general 中也没有任何内容。 我已经看过 this,但它并没有解决我的问题

编辑:我知道我应该使用 CommandHandler class 而不是将所有命令放在那里。我以后不会这样做了,但这只是为了测试。

我知道这很愚蠢,但你检查过机器人发帖权限了吗? (这发生在我身上。)

我将您的代码复制到我的一个测试机器人并稍作更改,我的机器人能够连接,只是它没有响应命令。
这些是我改变的:

第一次改变

MyBot bot = new MyBot(token); //instead of MyBot bot = MyBot(token);

我更改了它,因为我遇到了这个错误:

第二次更改:机器人没有响应命令

Console.WriteLine("[BOT] Connecting...");
            discord.ExecuteAndWait(async () =>
            {
                await discord.Connect(botToken, TokenType.Bot);
            });

上面这段代码放错地方了,所以移到了下面

commands.CreateCommand("info").Do(async (e) =>
        {
            Console.WriteLine("!info executed");
            await e.Channel.SendMessage("Coding Bot");
        });

所以最后会放在这里:

其他细节:检查你的.NET框架版本,我测试这段代码时使用的是4.6.2,API Discord.NET版本是在 0.9.6

如果问题仍然存在,您可以在这里寻求帮助:https://discord.gg/JBp6gSN

略记
此外,最近发布了 Discord.NET 的最新版本 v1.0.0。它涉及从 v1 到 v0.9.6 的重大更改,使所有内容 运行 都基于异步。如果这个问题让您很头疼,您可以使用 Discord.NET v1 来轻松摆脱这种情况。