M
M
Mind20772021-04-30 11:58:29
Python
Mind2077, 2021-04-30 11:58:29

How to delete a channel knowing its name in discord.py?

I am making a system of private voice channels. Problems arose with the removal of the channel. Help solve
Code:

@bot.command()
async def delete(ctx):
    channel=f"{ctx.message.author}'s channel"
    await bot.delete_channel(channel)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-04-30
@SoreMix

delete_channel

Basically there is no such method.
@bot.command()
async def delete(ctx):
    channel_name = f'{ctx.message.author}\'s channel'
    channel = discord.utils.get(ctx.guild.channels, name=channel_name)
    
    if channel:
        await channel.delete()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question