Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning and Deleting a channel: Discord.py

@client.command()
@commands.is_owner()
async def nuke(ctx, channel_name):
    existing_channel = discord.utils.get(guild.channels, name=channel_name)
    if existing_channel is not None:
        await clone(name=channel_name,reason="Has been nuked")
        await existing_channel.delete()
    else:
        await ctx.send(f'No channel named **{channel_name}** was found')

I've seen multiple bots on discord that can already do this, via a nuke command, but I wanted to learn how to do this myself. The problem is, my bot is unable to detect that I've mentioned a channel (as seen in the attached image). I found a question similar to this about 'nuking a channel properly' but they were using cogs. Help? This is the attached picture

like image 535
Bagle Avatar asked Feb 03 '26 01:02

Bagle


2 Answers

You're using clone() wrong, its Channel.clone() not only clone()

Below is the revised code

@client.command()
@commands.is_owner()
async def nuke(ctx, channel_name):
    existing_channel = discord.utils.get(guild.channels, name=channel_name)
    if existing_channel is not None:
        await existing_channel.clone(reason="Has been nuked")
        await existing_channel.delete()
    else:
        await ctx.send(f'No channel named **{channel_name}** was found')
like image 77
Just for fun Avatar answered Feb 04 '26 14:02

Just for fun


Just for fun already pointed out that you have been using the wrong command to clone. I'm using their code, but putting in the change where you wanted the channel name to be the clickable #example-channel.

When tagging a channel, the bot sees: <#123456789>, not #example-channel. We need only the numbers so we can get the channel ID. The first two lines of the code.

@client.command()
@commands.is_owner()
async def nuke(ctx, channel_name):
    channel_id = int(''.join(i for i in channel_name if i.isdigit())) 
    existing_channel = client.get_channel(channel_id)
    if existing_channel:
        await existing_channel.clone(reason="Has been nuked")
        await existing_channel.delete()
    else:
        await ctx.send(f'No channel named **{channel_name}** was found')


A good idea when trying to debug is to print() the different objects so you can see what they are.

print(channel_name) will show you what the bot sees when you tag. You might be able to see from that why it's not finding any 'channel name'.

like image 43
AbdurJ Avatar answered Feb 04 '26 13:02

AbdurJ



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!