2024-09-29 22:44:17 发布
网友
如何删除discord.py中id为的频道? 我所说的频道是指语音、文本和分类频道 我试过使用Guild.channel.delete(channel_id),但它不起作用,也没有问题
Guild.channel.delete(channel_id)
@client.command() async def removechannel(ctx, channel_id): removeChannel(channel_id)
显然removeChannel不是一个有效的函数,我想知道怎么做 请不要把这些文档链接到我这里,我已经为此挣扎了好几天了
removeChannel
如果将参数类型设置为TextChannel,则可以在命令中提及它,而不必写入ID,尽管ID也可以工作-!removechannel #general。TextChannel对象有一个delete()方法,您可以这样使用:
TextChannel
!removechannel #general
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()
如果将参数类型设置为
TextChannel
,则可以在命令中提及它,而不必写入ID,尽管ID也可以工作-!removechannel #general
。TextChannel
对象有一个delete()
方法,您可以这样使用:如果您愿意,还可以通过ID使其工作(对于语音频道,您不能提及它们):
参考文献:
Client.get_channel()
返回相关问题 更多 >
编程相关推荐