简体   繁体   English

发挥作用的Discord.py Reaction机器人

[英]Discord.py Reaction bot that gives a role

How do I make a bot that would give people roles when they reacted to a specific thing? 当人们对特定事物做出反应时,我该如何打造一个能够赋予人们角色的机器人? So far I have this but it does not work 到目前为止,我有这个但它不起作用

@client.event
async def on_ready():
    channel = client.get_channel('513546504481406979')
    role = discord.utils.get(user.server.roles, name="testrole")
    message = await bot.send_message(channel, "React to me!")
    while True:
        reaction = await bot.wait_for_reaction(emoji="👍", message=message)
        await bot.add_roles(reaction.message.author, role)

wait_for_reaction returns a (reaction, user) tuple. wait_for_reaction返回一个(reaction, user)元组。 You only need the user portion to assign the role: 您只需要user部分来分配角色:

reaction, reactor = await bot.wait_for_reaction(emoji="👍", message=message)
await bot.add_roles(reactor, role)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM