如何删除discord.py中id为的频道?

2024-09-29 22:44:17 发布

您现在位置:Python中文网/ 问答频道 /正文

如何删除discord.py中id为的频道? 我所说的频道是指语音、文本和分类频道 我试过使用Guild.channel.delete(channel_id),但它不起作用,也没有问题

@client.command()
async def removechannel(ctx, channel_id):
    removeChannel(channel_id)

显然removeChannel不是一个有效的函数,我想知道怎么做 请不要把这些文档链接到我这里,我已经为此挣扎了好几天了


Tags: py文本clientidasyncdefchannel分类
1条回答
网友
1楼 · 发布于 2024-09-29 22:44:17

如果将参数类型设置为TextChannel,则可以在命令中提及它,而不必写入ID,尽管ID也可以工作-!removechannel #general
TextChannel对象有一个delete()方法,您可以这样使用:

@client.command()
async def removechannel(ctx, channel: discord.TextChannel):
    await channel.delete()
    await ctx.send("Successfully deleted the channel!")

如果您愿意,还可以通过ID使其工作(对于语音频道,您不能提及它们):

@client.command()
async def removechannel(ctx, channel_id: int):
    channel = client.get_channel(channel_id)
    await channel.delete()
    await ctx.send("Successfully deleted the channel!")

参考文献:

  • ^{}-从Client.get_channel()返回
  • ^{}-所有公会频道(文本频道、语音频道、类别)将继承此方法
  • ^{}

相关问题 更多 >

    热门问题