Discord Bot [C #] does not execute command

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, . , .

+4
2

, , .
, :

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

, : enter image description here

:

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");
        });

, : enter image description here

: .NET Framework, 4.6.2 , API Discord.NET - 0.9.6

, : https://discord.gg/JBp6gSN


, Discord.NET, 1.0. v1 v0.9.6, async. , , Discord.NET v1.

+2

, , , ? ( .)

+2

Source: https://habr.com/ru/post/1668853/


All Articles