【问题标题】:Give role to user in message在消息中为用户赋予角色
【发布时间】:2021-04-17 06:35:32
【问题描述】:
print("dsdsdd")
import discord
import time
from discord.ext import commands
from discord.utils import get

TOKEN = "..."
ROLE = "Rekrutant"
bot = commands.Bot(command_prefix = "/")

@bot.event
async def on_ready():
    print("Zalogowano: " + bot.user.name)

@bot.command()
async def setup(ctx, user: discord.Member = None):
        ADMIN_ROLE = discord.utils.get(ctx.guild.roles, name="Admin")
        if (ADMIN_ROLE in ctx.author.roles):
            await user.add_roles("Rozmowy+")
        else:
            await ctx.send("Nie masz uprawnien, aby uzywac komendy")

bot.run(TOKEN)

我在获取用户表单消息时遇到问题。

我收到一个错误: 等待请求(guild_id,user_id,role.id,reason=reason) AttributeError:“str”对象没有属性“id”

我不知道为什么它不起作用。

【问题讨论】:

    标签: python discord


    【解决方案1】:

    这是因为您将一个字符串放入 add_roles 函数中,而该函数确实需要一个角色对象。试试:

    await ctx.author.add_roles(discord.utils.get(ctx.guild.roles,name="Rozmowy+"))
    

    这个新函数将字符串转换为角色对象,这正是原始函数所要寻找的。此外,我将用户更改为 ctx.author,因为这是唯一对我有用的用户对象。如果您需要任何澄清,请在下面的评论中问我。

    【讨论】:

      猜你喜欢
      • 2020-01-07
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2022-08-22
      • 2021-07-26
      • 2018-07-20
      相关资源
      最近更新 更多