简体   繁体   English

Discord.py 创建一个新的频道和角色关闭模板

[英]Discord.py Creating a new channel and role of off a template

So im trying to create a channel and a role based on what the user asked for in the command.所以我试图根据用户在命令中的要求创建一个频道和一个角色。

As an example:举个例子:

User: >newrealm (realmname) (emoji)

So far I have this:到目前为止,我有这个:

@commands.command()
  async def newrealm(self, ctx,* , reason):
    reason = reason.split(' ')
    realm, emoji = reason
    author = ctx.message.author
    guild = ctx.message.guild
    color = discord.Colour(0x3498DB)
    await guild.create_role(name= realm + " OP", color = color)
    await guild.create_text_channel(realm + emoji, category = 777360644252762123) #issue here
    await ctx.send("Created Channel and Role!")

But I am getting a traceback there.但我在那里得到了追溯。

Ignoring exception in command newrealm:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/runner/SolarisTurtleMain/cogs/RealmCMD.py", line 55, in newrealm
    await guild.create_text_channel(realm + emoji, category = 777360644252762123)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 905, in create_text_channel
    data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 823, in _create_channel
    parent_id = category.id if category else None
AttributeError: 'int' object has no attribute 'id'

The category argument is expecting a CategoryChannel object but you're passing it an int . category参数需要一个CategoryChannel对象,但您将它传递给int You can use get_channel to get the CategoryChannel :您可以使用get_channel来获取CategoryChannel

category_channel = guild.get_channel(777360644252762123)

Then pass it to the create_text_channel function:然后将其传递给create_text_channel函数:

await guild.create_text_channel(realm + emoji, category = category_channel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM