首页 > 解决方案 > Discord Bot [C#] Bot Responds to Commands but then Doesn't Continue?

问题描述

The bot in Discord

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!

标签: c#discorddsharp+

解决方案


推荐阅读