为了账号安全,请及时绑定邮箱和手机立即绑定

如何让我的不和谐机器人在发送消息后给我角色?

如何让我的不和谐机器人在发送消息后给我角色?

HUWWW 2023-10-06 13:47:25
你好,我正在制作一个机器人,当你输入消息时,它会给你角色,但我的代码不起作用,它总是给出这个错误文件“Rgiver.py”,第32行,在on_message角色=discord.utils.get(server.guild.roles,name =“Admin”)NameError:名称'服务器'未定义这是我的代码async def on_message(message):    member = message.author    if member.bot:        return    if message.attachments:        return    print(message.content)    print(str(message.author))    if "role" in message.content:        embed=discord.Embed(title="Giving role.", color=0x00ff40)        await message.channel.send(message.channel, embed=embed)        role = discord.utils.get(server.guild.roles, name="Admin")        await client.add_roles(message.author, role)
查看完整描述

1 回答

?
叮当猫咪

TA贡献1776条经验 获得超12个赞

什么是server.guild.roles,你可能的意思是message.guild.roles

另外,您的用法是错误的,请参阅add_rolesadd_roles的文档,您可能的意思是message.author.add_roles(...)


查看完整回答
反对 回复 2023-10-06
  • 1 回答
  • 0 关注
  • 82 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信