Как я могу проверить, есть ли у пользователя роль модератора в dsharp +? - PullRequest
0 голосов
/ 04 мая 2020

Вот команда, которая у меня есть, и я хочу, чтобы она проверяла, есть ли у пользователя определенная роль, чтобы использовать команду.

[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.GetInteractivityModule();

    // 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 != null)
    {
        // announce the winner
        await ctx.RespondAsync($"And the winner is: {msg.Message.Author.Mention}");
    }
    else
    {
        await ctx.RespondAsync("Nobody? Really?");
    }
}
...