python - 石头剪刀布 Discord.py
问题描述
所以我试图在我的 discord.py 机器人上创建一个剪刀石头布命令,但不是发送响应,而是使用响应,而是响应它自己的响应。试过 代码是
async def rps(self, ctx):
global RPS_START, RPS_AUTHOR, channel
channel = ctx.channel
embed = discord.Embed(title="**Rock Paper Scissor**")
msg = await ctx.send(embed=embed)
await msg.add_reaction('')
await msg.add_reaction('')
await msg.add_reaction('✂')
RPS_START = True
RPS_AUTHOR = ctx.message.author
@commands.Cog.listener()
async def on_raw_reaction_add(self, reaction):
global RPS_START, RPS_AUTHOR, human_decision, channel, reply
if RPS_START is False and reaction.member != RPS_AUTHOR and not reaction.member.bot:
return
elif reaction.emoji.name == '':
human_decision = 'rock'
elif reaction.emoji.name == '':
human_decision = 'paper'
elif reaction.emoji.name == '✂':
human_decision = 'scissor'
RPS_START = False
rock_paper_scissors = ('rock', 'paper', 'scissor')
bot_decision = (random.choice(rock_paper_scissors)).lower()
if human_decision in ['rock', 'paper', 'scissor']:
if human_decision == bot_decision:
reply = 'tie'
elif human_decision == 'rock' and bot_decision == 'paper':
reply = 'lost'
elif human_decision == 'paper' and bot_decision == 'rock':
reply = 'win'
elif human_decision == 'scissor' and bot_decision == 'paper':
reply = 'win'
elif human_decision == 'paper' and bot_decision == 'scissor':
reply = 'lost'
elif human_decision == 'stone' and bot_decision == 'scissor':
reply = 'win'
elif human_decision == 'scissor' and bot_decision == 'rock':
reply = 'lost'```
解决方案
在您的活动开始时使用一个简单的 if 语句on_raw_reaction_add
应该可以解决问题:
if reaction.member.bot:
return
reaction
此外,当您用作变量的名称时,您可能会感到非常困惑。在文档中它被声明为payload
所以你应该考虑改变它。
推荐阅读
- powerbi - 如何在 power bi 中进行迭代?
- ios - iOS中推送通知的振动取决于客户端或有效负载
- android - 无法按位置生成 Firebase 受众
- assembly - 了解汇编中的 callq 指令
- firebase - Firebase.ServerValue.increment() 在本机反应中不可用吗?
- javascript - getElementById 在将其应用于选择选项时返回 null
- java - Windows 环境变量 NUMBER_OF_PROCESSORS 在 JVM 内外显示不同的值
- python - Python random.expovariate() 零除错误
- python - 在python中使用带有正则表达式的多个变量
- amazon-web-services - 在每次应用中重新创建 Terraform aws_spot_instance_request