在 Spambot Discord C# 中出现错误 "A MessageReceived handler is blocking the gateway task."

Getting error "A MessageReceived handler is blocking the gateway task." In Spambot Discord C#

在这个命令中,我希望用户输入一个整数,然后字符串he/she 想要垃圾邮件。在它询问字符串后,我在 CMD 中收到一条错误消息 "A MessageReceived handler is blocking the gateway task."

例如用户可以说

!spamstring 29

然后

快来CSGO吧!

该机器人将发送垃圾邮件 加入 CSGO! 29 次。这是代码:

[Command("spamstring")]
public async Task spamstring([Remainder] int times)
{
    var user = Context.Client.GetUser(Context.User.Id);
    if (times > 68)
    {
        await Context.Channel.SendMessageAsync("*YOU CANNOT GO OVER 69* :eggplant: ");
    }
    else
    {
        await Context.Channel.SendMessageAsync("You chose to spam " + times + " times, what do you want to spam?");
        string message = Console.ReadLine();
        if (message.Contains("@everyone"))
        {
            await Context.Channel.SendMessageAsync("Do not mention everyone!");
        }
        else
        {
            await Context.Channel.SendMessageAsync(":fire: *SPAMMING* :fire: ");
            for (int i = 0; i < times; i++)
            {
                await Context.Channel.SendMessageAsync(message);
                System.Threading.Thread.Sleep(1500);
            }
        }
    }
}

我保留了基础知识,但是在尝试调试他的代码时,这个特定的命令破坏了一切,所以我重写了它。我首先改变了他在 public 任务 中接受 "message" 的方式。他尝试使用稍后在函数中调用的字符串,但该字符串不起作用,并尝试读取控制台。这是行不通的,因为 Discord 在被识别为命令之前不会记录任何内容,因此我将其更改为参数。从那里开始很简单,我没有使用 Context,Channel.SendMessageAsync,而是简单地使用了 ReplyAsync。我还添加了一个别名。另外,我没有使用行不通的 message.Contains(),而是使用了 if (messageToString() == "@everyone").

[Command("spamstring")]
    [Alias("sp", "spamming", "juanspam")]
    public async Task spamming(int times, string message)
    {
        //try and refrain from BIG if statements like this
        if (times > 68)
        {
            await Context.Message.DeleteAsync();
            await ReplyAsync(Context.User.Mention + " *YOU CANNOT GO OVER 69* :eggplant:");
        }
        else
        {
            await Context.Message.DeleteAsync();
            await ReplyAsync("You chose to spam " + times + " times, what do you want to spam?");


            //NEW IF
            if (message.ToString() == "@everyone")
            {
                await ReplyAsync("Don't do that bitch. You deserve to be spammed for that!");
            }
            else
            {
                await Context.Channel.SendMessageAsync(":fire: *SPAMMING* :fire: ");

                //spam loop
                for (int i = 0; i < times; i++)
                {
                    await Context.Channel.SendMessageAsync(message);
                    System.Threading.Thread.Sleep(1500);
                }
            }


        }
       //END BIG OF
    }
}

}