【发布时间】:2019-11-06 02:32:15
【问题描述】:
我正在尝试制作一个 Discord 机器人,当你键入 !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 不存在?
【问题讨论】:
-
正如回溯所说:“Bot”对象没有“add_roles”属性。
标签: python discord.py