简体   繁体   中英

discord.py bot - Nuke command not working

I am having issues with my nuke command which is supposed to delete the current channel and clone it, clearing all the messages. The problem is that it doesn't work at all and doesn't give any errors!

Code

@client.command()
@commands.has_permissions(administrator=True)
async def nuke(ctx):
    embed = discord.Embed(
        colour=discord.Colour.blue,
        title=f":boom: Channel ({ctx.channel.name}) has been nuked :boom:",
        description=f"Nuked by: {ctx.author.name}#{ctx.author.discriminator}"
    )
    nuke_ch = discord.utils.get(ctx.guild.channels, name=ctx.channel.name)
    new_ch = await nuke_ch.clone(reason="Being nuked and remade!")
    await nuke_ch.delete()
    sendem = new_ch.send(embed=embed)
    await asyncio.sleep(3)
    sendem.delete()

If you have a solution, please answer this question. Thanks in advance.

Remember to also request nuke_ch as an argument in your command. You just work with ctx , nothing more.

Here is a nuke command that I used to work with:

@client.command()
@commands.has_permissions(administrator=True)
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) # Get channel ID
    if existing_channel:
        await ctx.send("**This channel will be nuked in X seconds.**")
        await asyncio.sleep(YourValue) # Can be removed
        await existing_channel.delete() # Deletes the old channel
        existing = await existing_channel.clone() # Clones the channel again
        await existing.send("**This channel was nuked/re-created!**") 

    else:
        await ctx.send(f'**No channel named `{channel_name}` was found.**')

What did we do?

  • Get the channel by ID or name
  • Check if the channel exists and then nuke it
  • Built in an error handler if the channel was not found

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