不和谐机器人蟒蛇add_roles



我正在尝试制作一个不和谐的机器人,当您键入!join时,它会为您提供"成员"角色。

我在add_roles上遇到问题.

from discord.ext import commands
import os
from webserver import keep_alive
bot = commands.Bot(command_prefix = "!")
bot.remove_command('help')
@bot.event
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, name="OG")
await member.add_roles(role)
@bot.event
async def on_ready():
print("yeay eyea")

@bot.command(pass_context=True)
async def join(ctx):
member = ctx.message.author
role = discord.utils.get(member.guild.roles, name="Member")
await bot.add_roles(member, role)
keep_alive()
TOKEN = os.environ.get("NjQwMTQaaaaaaaaaaaaaaaaaaaA4qHkx3Tl-l3CbpX8kTICfA")
bot.run("NaaaaaaaaaaaaaTICfA")

这是我尝试使用命令时遇到的错误"!join"

Ignoring exception in command join:Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/ext
/commands/core.py", line 79, in wrapped    ret = await coro(*args, **kwargs)
File "main.py", line 23, in join
await bot.add_roles(member, role)AttributeError: 'Bot' object has no attribute 'add_roles'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError:'Bot' object has no attribute 'add_roles'

add_roles不存在?

抱歉,我正在回答而不是评论,但由于我的代表次数少,我无法发表评论。您收到的错误是因为协程来自成员类。所以你需要做member.add_roles(member, role)而不是bot.add_roles()编辑:另外,请确保删除/更改您的令牌,因为它允许人们更改您的机器人代码并基本上劫持您的机器人。

最新更新