Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py How To Delete Every Text-Channel?

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)

like image 770
fakdofjF FDASJOFADSF Avatar asked Feb 01 '26 03:02

fakdofjF FDASJOFADSF


1 Answers

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.

Be careful

guild.channels calls all channels, not only Textchannels.
To call Textchannels only, use guild.text_channels.

like image 148
Thörni Avatar answered Feb 02 '26 17:02

Thörni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!