AttributeError: 'int' object has no attribute 'id' discord.py

AttributeError: 'int' object has no attribute 'id' discord.py

我正在尝试创建一个 discord.py 函数来创建一个带有用户名称的 'secret' 频道,但是每当我 运行 函数

我收到这个错误

in _create_channel parent_id = category.id if category else None AttributeError: 'int' object has no attribute 'id'

想知道为什么会出现 int 或 id 错误,因为我没有尝试使用对象或属性

代码如下:

@client.command()
async def channel(ctx, user : discord.User):
  perms = {
    ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
    user: discord.PermissionOverwrite(read_messages=True)}
  await ctx.guild.create_text_channel("♥~ " + user.name +" ~♥", category=category, overwrites = perms)

尝试

 await ctx.guild.create_text_channel('♥~ " + user.name +" ~♥', category=category, overwrites = perms)

假设 category 是类别 ID。您需要从 ctx.guild.categories 获取 CategoryChannel 对象并将其作为 category 传递给 create_text_channel().

category_channel = discord.utils.get(ctx.guild.categories, id=category)
await ctx.guild.create_text_channel("♥~ " + user.name +" ~♥", category=category_channel, overwrites = perms)