繁体   English   中英

discord.py bot - Nuke 命令不起作用

[英]discord.py bot - Nuke command not working

我的 nuke 命令出现问题,该命令应该删除当前频道并克隆它,清除所有消息。 问题是它根本不起作用并且没有给出任何错误!

代码

@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()

如果您有解决方案,请回答此问题。 提前致谢。

请记住在命令中还请求nuke_ch作为参数。 您只需使用ctx ,仅此而已。

这是我曾经使用过的一个nuke命令:

@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.**')

我们做了什么?

  • 通过 ID 或名称获取频道
  • 检查通道是否存在,然后对其进行核对
  • 如果未找到通道,则内置错误处理程序

暂无
暂无

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

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