Discord.py 如何删除每个文本频道?
Discord.py How To Delete Every Text-Channel?
我正在尝试创建一个命令,允许用户删除其服务器中的每个文本通道。 运行 这段代码出现错误。
AttributeError: 'Guild' object has no attribute 'delete_text_channel'
@client.command()
async def test(ctx):
guild = ctx.message.guild
for channel in guild.channels:
guild.delete_text_channel(channel)
使用await channel.delete()
.
如您的错误消息所述,对象 'Guild'
没有属性 'delete_text_channel'
正确的方法是:
@client.command()
async def test(ctx):
guild = ctx.guild
for channel in guild.channels:
await channel.delete()
或者,您可以添加删除邮件的原因,这将显示在审核日志中:
channel.delete("Because I can")
更多信息here
。
小心
guild.channels
调用所有频道,而不仅仅是文本频道。
要仅调用文本通道,请使用 guild.text_channels
.
您可以将 await channel.delete()
与此示例代码一起使用:
@client.command()
async def delete_channels(ctx):
[await channel.delete() for channel in ctx.guild.text_channels]
你可以简单地使用它。
我正在尝试创建一个命令,允许用户删除其服务器中的每个文本通道。 运行 这段代码出现错误。
AttributeError: 'Guild' object has no attribute 'delete_text_channel'
@client.command()
async def test(ctx):
guild = ctx.message.guild
for channel in guild.channels:
guild.delete_text_channel(channel)
使用await channel.delete()
.
如您的错误消息所述,对象 'Guild'
没有属性 'delete_text_channel'
正确的方法是:
@client.command()
async def test(ctx):
guild = ctx.guild
for channel in guild.channels:
await channel.delete()
或者,您可以添加删除邮件的原因,这将显示在审核日志中:
channel.delete("Because I can")
更多信息here
。
小心
guild.channels
调用所有频道,而不仅仅是文本频道。
要仅调用文本通道,请使用 guild.text_channels
.
您可以将 await channel.delete()
与此示例代码一起使用:
@client.command()
async def delete_channels(ctx):
[await channel.delete() for channel in ctx.guild.text_channels]
你可以简单地使用它。