简体   繁体   中英

How do i delete a channel in discord.py having its id?

How do i delete a channel in discord.py having its id? By channel i mean voice, text and category channels I tried with Guild.channel.delete(channel_id) but it's not working neither getting issues

@client.command()
async def removechannel(ctx, channel_id):
    removeChannel(channel_id)

Obviously removeChannel is not a valid funcion, i wanted to know how to do it Please do not link me the docs, it's been days that i'm struggling with this

If you set the argument type to be a TextChannel , you're able to mention it in the command instead of having to write the ID, although the ID will also work - !removechannel #general .
The TextChannel object has a delete() method that you can use like this:

@client.command()
async def removechannel(ctx, channel: discord.TextChannel):
    await channel.delete()
    await ctx.send("Successfully deleted the channel!")

You can also make it work via ID if you want (for voice channels, as you can't mention them):

@client.command()
async def removechannel(ctx, channel_id: int):
    channel = client.get_channel(channel_id)
    await channel.delete()
    await ctx.send("Successfully deleted the channel!")

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM