[英]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!")
参考:
abc.GuildChannel
- 从Client.get_channel()
返回GuildChannel.delete()
- 所有公会频道(文本频道、语音频道、类别)都将继承此方法。Client.get_channel()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.