Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete take certain channels and categories and delete them? (Discord.py)

I want that when a user writes a command, the bot deletes certain channels with certain names, but I don’t really succeed.
Error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'get_category'

Code:

@client.command()
async def verification_channels_delete(ctx):
    await ctx.send('Удаляю категории и каналы для верефикации...')
    #
    category1 = await ctx.message.guild.get_category('Verification')
    category2 = await ctx.message.guild.get_category("Chat")
    #
    await category1.delete()
    await category2.delete()
    #
    channel1 = await ctx.message.guild.get_text_channel("Verification")
    channel2 = await ctx.message.guild.get_text_channel("Chat")
    #
    await channel1.delete()
    await channel2.delete()
    #
    await ctx.send('Я удалил все каналы для верефикации!')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to get channel, category, or anything else by name you should use discord_utils for it:

from discord.utils import get

@client.command()
async def verification_channels_delete(ctx):
    category1 = get(ctx.guild.categories, name = "Verification")
    category2 = get(ctx.guild.categories, name = "Chat")
    await category1.delete()
    await category2.delete()

    channel1 = get(ctx.guild.text_channels, name = "verification")
    channel2 = get(ctx.guild.text_channels, name = "chat")
    await channel1.delete()
    await channel2.delete()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading