Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

c# - DSharpPlus (D#+) Adding Reactions To Messages With Bot For Game

I'm trying to make a bot that you can request to play rock paper scissors with another player. It asks the challenged player whether they want to play, if they accept, the bot then creates a message with 3 reactions that once reacted to by the relative player will delete itself and save the choice. Then it repeats for the other player. Then it says who won / drew.

public class Games : BaseCommandModule
{
    [Command("rps")]
    public async Task ReactionCommand(CommandContext ctx, DiscordMember member)
    {
        var emoji = DiscordEmoji.FromName(ctx.Client, ":scissors:");
        var challenger = ctx.Member;
        var opponent = member;
        var message = await ctx.RespondAsync($"{opponent.Mention}, react with {emoji} if you'd like to play Rock Paper Scissors with {challenger.DisplayName}?");
        await message.CreateReactionAsync(emoji);
        var result = await message.WaitForReactionAsync(opponent, emoji);
        if (!result.TimedOut)
        {
            var message2 = await ctx.RespondAsync($"{opponent.Mention}, react with your choice.");
            await message2.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":rock:"));
            await message2.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":scissors:"));
            await message2.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":roll_of_paper:"));
        }
    }

}

It does not add the reactions to the message. I am also wondering how I would be able to tell what reaction the person did. So the whole thing works for the part where it asks to confirm whether I want to play. I react with the scissors, then it says the 'member, react with your choice' but with no reactions. Thank you.

P.S. The console has no errors.

question from:https://stackoverflow.com/questions/66056222/dsharpplus-d-adding-reactions-to-messages-with-bot-for-game

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...