【发布时间】:2020-05-19 13:20:00
【问题描述】:
我正在尝试制作一个将在嵌入中发送的命令,并且该命令有两个反应,一个勾号和一个叉号,我想让用户只对其中一个反应做出反应,而不是对它们都做出反应。我还需要一些帮助来建立一个系统,以确保做出反应的人具有特定的角色。任何帮助将不胜感激!
【问题讨论】:
标签: python discord.py
我正在尝试制作一个将在嵌入中发送的命令,并且该命令有两个反应,一个勾号和一个叉号,我想让用户只对其中一个反应做出反应,而不是对它们都做出反应。我还需要一些帮助来建立一个系统,以确保做出反应的人具有特定的角色。任何帮助将不胜感激!
【问题讨论】:
标签: python discord.py
这可以使用on_raw_reaction_add() 事件来实现。
@bot.event
async def on_raw_reaction_add(payload): # checks whenever a reaction is added to a message
# whether the message is in the cache or not
# check which channel the reaction was added in
if payload.channel_id == 112233445566778899:
channel = await bot.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
# iterating through each reaction in the message
for r in message.reactions:
# checks the reactant isn't a bot and the emoji isn't the one they just reacted with
if payload.member in await r.users().flatten() and not payload.member.bot and str(r) != str(payload.emoji):
# removes the reaction
await message.remove_reaction(r.emoji, payload.member)
参考资料:
【讨论】:
我认为您可以存储 userId 或所有用户唯一的东西。 然后创建一个函数检查这个ID是否出现了不止一次或其他逻辑。
https://discordpy.readthedocs.io/en/latest/api.html#userUser API
在这里,您可以从该对象中获取用户 ID。
此外,您可以从客户收到的消息中获取作者 ID。
def on_message(message):
print(message.author.id)
【讨论】: