【问题标题】:How can I print the id of the newly created discord text channel?如何打印新创建的不和谐文本频道的 ID?
【发布时间】:2021-02-20 16:02:14
【问题描述】:

我对 python 和 discord 非常陌生。下面的代码用于在用户键入 $create 时创建一个新频道。我只需要以某种方式获取新创建的频道的频道 ID 并将其打印在我的终端上。请帮忙....

@bot.command(name='create')
async def create_channel(ctx, channel_name='New-temporary'):
    name = 'ideas'  # this name is for which channel to put it in
    category = discord.utils.get(ctx.guild.categories, name=name)
    guild = ctx.guild
    print(guild)
    print(f'Creating a new channel: {channel_name}')
    await asyncio.sleep(1)
    await guild.create_text_channel(channel_name, category=category)


bot.run(TOKEN)

【问题讨论】:

    标签: python discord channel


    【解决方案1】:

    create_text_channel 将返回刚刚创建的频道。可以通过如下方式获取id:

    channel = await guild.create_text_channel(channel_name, category=category)
    print(channel.id)
    

    【讨论】:

      猜你喜欢
      • 2020-11-07
      • 2021-11-23
      • 2020-09-06
      • 2021-10-25
      • 2020-12-28
      • 2021-02-24
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多