c# - Discord Bot [C#] Bot Responds to Commands but then Doesn't Continue?
问题描述
As you can see, it responds to the request, but then doesn't do anything with the number I've entered. It just sits there.
Here is my code for that command (currently it's just copied from the DSharp tutorial website, I planned to modify it significantly, but it won't even do the standard):
[Command("waitforcode"), Description("Waits for a response containing a generated code.")]
public async Task WaitForCode(CommandContext ctx)
{
// first retrieve the interactivity module from the client
var interactivity = ctx.Client.GetInteractivity();
// generate a code
var codebytes = new byte[8];
using (var rng = RandomNumberGenerator.Create())
rng.GetBytes(codebytes);
var code = BitConverter.ToString(codebytes).ToLower().Replace("-", "");
// announce the code
await ctx.RespondAsync($"The first one to type the following code gets a reward: `{code}`");
// wait for anyone who types it
var msg = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains(code), TimeSpan.FromSeconds(60));
if (!msg.TimedOut)
{
// announce the winner
await ctx.RespondAsync($"And the winner is: {msg.Result.Author.Mention}");
}
else
{
await ctx.RespondAsync("Nobody? Really?");
}
}
If anybody could help me, that would be great!
解决方案
推荐阅读
- typescript - 如何在 Typescript 中定义拒绝来自对象的键的通用函数?
- java - 变量“接口”可能尚未初始化
- yii2 - MaskedInput work at first element only - dynamic form wbraganca - Yii2
- c# - 如何在网格视图中显示特定列的标签消息?
- javascript - 在输入键上,提交表单
- php - Laravel 5 安装 wapnen/google-cloud-vision-php 时出错
- algorithm - Clojure 中指定大小的随机 AST 生成
- cakephp - CakePHP 3.6 TreeBehavior 结束 DataTables RowReorder 不保存新位置
- c++ - 从浮点数中删除小数部分但保留类型的有效方法
- c++ - 我们可以使用运算符重载来改变减号的行为吗