【问题标题】:Discord.py I am looking for make command to set role for everyone using the commandDiscord.py 我正在寻找使用该命令为每个人设置角色的 make 命令
【发布时间】:2020-11-17 15:19:21
【问题描述】:
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')

【问题讨论】:

  • 使用 guild 而不是 server 他们更新到最新版本的 discord.py\

标签: python discord.py


【解决方案1】:

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)

【讨论】:

  • (discord.ext.commands.errors.CommandInvokeError: Command raise an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions ) 当我编辑我的代码时这个错误信息:(跨度>
猜你喜欢
  • 2021-02-07
  • 2021-07-06
  • 2021-04-08
  • 2022-06-10
  • 2021-04-09
  • 2021-07-30
  • 2020-09-26
  • 2021-08-07
  • 2021-04-12
相关资源
最近更新 更多