【发布时间】:2020-10-25 21:50:43
【问题描述】:
赋予角色正确。但是绝对复制的“on_reaction_remove”没有给出任何结果,甚至是例外。我尝试在第二个帐户中选择反应,是的,机器人提供了一个角色,但是当我删除反应机器人时没有做任何事情:/
import discord
from discord import utils
from discord.ext import commands
import config
client = commands.Bot(command_prefix = '#')
@client.event
async def on_ready():
print('Logged on as {0}!'.format(client.user.name))
@client.event
async def on_reaction_add(reaction, user):
if str(reaction.message.channel) == 'giving-roles':
try:
channel = reaction.message.channel
role = utils.get(user.guild.roles, id = config.ROLES[str(reaction)])
await user.add_roles(role)
print(f'[SUCCESS] Role [{config.ROLES[str(reaction)]} for [{user}] was added ')
except Exception as e:
print(repr(e))
@client.event
async def on_reaction_remove(reaction, user):
if str(reaction.message.channel) == 'giving-roles':
try:
channel = reaction.message.channel
role = utils.get(user.guild.roles, id = config.ROLES[str(reaction)])
await user.remove_roles(role)
print(f'[SUCCESS] Role [{config.ROLES[str(reaction)]} for [{user}] was removed ')
except Exception as e:
print(repr(e))
# RUN
client.run(config.TOKEN)
【问题讨论】:
-
如果去掉try和except,会不会产生错误?
标签: python-3.x discord.py