python - Discord.py 我正在寻找使用命令为每个人设置角色的 make 命令
问题描述
import discord
from discord.utils import get
client = commands.Bot(command_prefix="!")
@client.command(pass_context=True)
async def addrole(ctx):
user = ctx.message.author
role = discord.utils.get(user.server.roles, name="Open")
await ctx.add_roles(user, role)
但是当我使用这个命令时。我收到此错误(discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'Member'对象没有属性'server')
解决方案
server
更改为guild
及其Member.add_roles()
以下是修改后的代码:
import discord
from discord.utils import get
client = commands.Bot(command_prefix="!")
@client.command()
async def addrole(ctx):
role = get(ctx.guild.roles, name="Open")
await ctx.author.add_roles(role)
推荐阅读
- java - 未设置位置
- ios - Swift UITableView detailTextLabel 不起作用
- php - PHP中具有多个条件的while循环
- android - 如果我使用 GoogleSignIn + DriveClient,如何执行后台同步任务
- python - 在长度等于某个值的列表列表中查找列表
- reactjs - 状态更新错误
- node.js - 如何设置 Socket.io 以使用 Express NodeJS 监听单独的页面
- debugging - 在 GoLand 的控制台中运行 termbox-go 应用程序
- arrays - JSON Parse 错误:无法在 React Native 中解析 JSON 字符串
- php - Woocommerce:在商店页面使用图库图片作为产品图片