在此命令中,我希望用户输入一个整数,然后输入他/她想要垃圾邮件的字符串。在询问字符串之后,我在CMD中收到一条错误,说“" MessageReceived处理程序正在阻止网关任务。”#34;
例如,用户可以说
!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);
}
}
}
}
答案 0 :(得分:0)
我保留了基础知识,但在尝试调试他的代码时,这个特殊命令打破了所有内容,所以我只是重写了它。我开始改变他对公共任务中“消息”的看法。他尝试在函数中使用稍后调用的字符串,该字符串不起作用并尝试读取控制台。这不起作用,因为Discord在被识别为命令之前不会记录任何内容,因此我将其更改为参数。从那里它很简单,而不是使用 Context,Channel.SendMessageAsync 我只是做了 ReplyAsync 。我还添加了一个Alias。此外,我没有使用 message.Contains(),而是使用了if(messageToString()==“@ everyvery”)的if语句。
[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
}
}
}