【问题标题】:discord.py bot - Nuke command not workingdiscord.py bot - Nuke 命令不起作用
【发布时间】:2021-04-05 03:47:33
【问题描述】:

我的 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()

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

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    请记住,还要在命令中请求 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 或名称获取频道
    • 检查通道是否存在,然后对其进行核对
    • 如果找不到通道,则内置错误处理程序

    【讨论】:

    • 不需要这个。我得到了我的答案 just ctx
    • @TigerNinja “如果你有解决方案”所以我给了你我的。
    猜你喜欢
    • 2020-08-16
    • 2019-07-23
    • 2021-03-30
    • 2021-01-02
    • 1970-01-01
    • 2020-10-13
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多