im试图制作一个不和谐的bot,当您输入!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不存在?
答案 0 :(得分:0)
很抱歉,我是在回答问题,而不是发表评论,但由于答辩率低,我无法发表评论。您收到的错误是因为该协同例程来自成员类。因此,您需要执行member.add_roles(member, role)
而不是bot.add_roles()
编辑:另外,请确保删除/更改您的令牌,因为它允许人们更改您的机器人代码并从本质上劫持您的机器人。