Reputation: 45
I'm trying to create a command that allows the user to delete every Text-Channel in their server. I've got an error when running this piece of code.
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)
Upvotes: 3
Views: 2106
Reputation: 555
Use await channel.delete()
.
As your error message sais, the object 'Guild'
has no attribute 'delete_text_channel'
The correct way would be:
@client.command()
async def test(ctx):
guild = ctx.guild
for channel in guild.channels:
await channel.delete()
Alternatively, you can add a reason why you deleted the message, which would show up in the audit log:
channel.delete("Because I can")
More information here
.
guild.channels
calls all channels, not only Textchannels.
To call Textchannels only, use guild.text_channels
.
Upvotes: 2
Reputation: 4743
You can use await channel.delete()
with this example code:
@client.command()
async def delete_channels(ctx):
[await channel.delete() for channel in ctx.guild.text_channels]
You can simply use that.
Upvotes: 2