来源<<ul>不和消息/gh>
我的意思是,如果你向bot发送一个DM,那么它就会在某个服务器上分配一个角色。
这是我尝试的代码:
@bot.event
async def on_message(message):
if message.author.bot:
return
elif message.content.startswith("++neunundvierzig++"):
role = message.author.guild.get_role(861543456908640298)
guild = bot.get_guild(816021180435529758)
await message.channel.send("Erfolgreich Zerifiziert!")
await member.add_roles(role)
日志中说:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:Usersaaa12AppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesdiscordclient.py", line 343, in _run_event
await coro(*args, **kwargs)
File "f:HTML CSS JS Py ProjektePythonbot_checkbot.py", line 36, in on_message
role = message.author.guild.get_role(861543456908640298)
AttributeError: 'User' object has no attribute 'guild'
我认为您对role
的定义是错误的。您的代码说message.author.guild
不存在,所以您应该尝试message.guild
。
:
role = message.guild.get_role(861543456908640298)
除此之外,您没有定义member
。只需将其重命名为await message.author.add_roles(role)
而不是await member.add_roles(role)
来源<<ul>