繁体   English   中英

如何删除 discord.py 中具有其 ID 的频道?

[英]How do i delete a channel in discord.py having its id?

如何删除 discord.py 中具有其 ID 的频道? 我所说的频道是指我尝试使用Guild.channel.delete(channel_id)的语音、文本和类别频道,但它既没有工作也没有问题

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

显然removeChannel不是一个有效的功能,我想知道怎么做请不要链接我的文档,我已经为此苦苦挣扎了几天

如果将参数类型设置为TextChannel ,则可以在命令中提及它,而不必编写 ID,尽管 ID 也可以使用 - !removechannel #general
TextChannel object 有一个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!")

参考:

暂无
暂无

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

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