I want that when a user writes a command, the bot deletes certain channels with certain names, but I can't 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('Я удалил все каналы для верефикации!')
CodePudding user response:
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()