这是带有错误的代码:
if message.content == "Test":
member = message.author
role = discord.utils.get(member.guild.roles, id="Character Created")
await bot.add_roles(member, role)
这是我的导入(以前将“ bot”定义为Discord.Client(),但我将其替换为bot导入):
import discord
import asyncio
from discord.ext import commands
import os
from discord.utils import get
from discord.ext.commands import bot
这是错误消息:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\User\Desktop\idlerpgtest.py", line 41, in on_message
await bot.add_roles(member, role)
AttributeError: module 'discord.ext.commands.bot' has no attribute 'add_roles'
答案 0 :(得分:0)
由于bot
没有属性add_roles
,discord.Member
没有属性,因此无法使用。因此,您可以这样做:
if message.content == "Test":
member = message.author
role = discord.utils.get(member.guild.roles, id="Character Created")
await member.add_roles(role)