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))刪除第二個(gè)message.author修復(fù)此問(wèn)題時(shí)添加角色,因此應(yīng)該是: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))屬性錯(cuò)誤: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'名稱錯(cuò)誤: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所有相關(guān)代碼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 回答

月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
on_message中的Message對(duì)象應(yīng)包含 message.author 中的 Member 對(duì)象,因此您可以執(zhí)行以下操作:
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貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
過(guò)去,我是通過(guò)調(diào)用消息來(lái)完成此操作add_roles
的author
。在你的情況下,它會(huì)是這樣的:
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)
我認(rèn)為我沒(méi)有包含一個(gè)reason
論點(diǎn),所以我不確定這種形式是否會(huì)采用該論點(diǎn),但如果其他形式這樣做,我認(rèn)為會(huì)的。
添加回答
舉報(bào)
0/150
提交
取消