Discord 试图message.author在使用await message.author.add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))删除第二个message.author修复此问题时添加角色,因此应该是:await message.author.add_roles(role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))属性错误:Traceback (most recent call last): File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs) File "C:\Users\Me\Desktop\Productive\Programming Projects\Python 3\Other\MyBot\bot.py", line 41, in on_message await bot.add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))AttributeError: 'Client' object has no attribute 'add_roles'名称错误:Ignoring exception in on_messageTraceback (most recent call last): File "C:\Users\Me\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs) File "C:\Users\Me\Desktop\Productive\Programming Projects\Python 3\Other\MyBot\bot.py", line 41, in on_message await add_roles(message.author,role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))NameError: name 'add_roles' is not defined所有相关代码import discord;from discord.utils import getfrom datetime import datetimebot=discord.Client()@bot.eventasync def on_ready(): print('Logged in') print('Username: %s' % (bot.user.name)) print('Userid: %s' % (bot.user.id))
2 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
on_message中的Message对象应包含 message.author 中的 Member 对象,因此您可以执行以下操作:
await message.author.add_roles(role, reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time))
陪伴而非守候
TA贡献1757条经验 获得超8个赞
过去,我是通过调用消息来完成此操作add_roles
的author
。在你的情况下,它会是这样的:
await message.author.add_roles(role,reason='Reason: Used \'%s\' in \'%s\ , on %s/%s/%s (day,month,year) at %s' % (word, str(message.channel),day,month,year,time)
我认为我没有包含一个reason
论点,所以我不确定这种形式是否会采用该论点,但如果其他形式这样做,我认为会的。
添加回答
举报
0/150
提交
取消