【问题标题】:How to delete the current channel of the command. Discord.py如何删除命令的当前通道。不和谐.py
【发布时间】:2021-06-14 12:49:38
【问题描述】:

所以我正在创建一个命令来删除运行它的通道。 我的代码是这样的:

@client.command()
async def deletecurrent(ctx):
await ctx.send('Deleting..')
#Delete current channel code here

【问题讨论】:

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


【解决方案1】:

我什至不会采取额外的步骤来通过 .get() 方法获取当前频道。

当前通道对象通过 ctx 对象传递给您。它包含 ctx.channel

所以删除当前频道的代码是:

await ctx.channel.delete()

【讨论】:

    【解决方案2】:

    哦,我找到了方法!不是最好的解决方案,但在这里仍然有效:

    channel = discord.utils.get(ctx.guild.channels, name=ctx.channel.name)
    channel_id = channel.id
    
    stch = client.get_channel(channel_id)
    await stch.delete()
    

    【讨论】:

    • 前三行没用,只需要await ctx.channel.delete()。我不确定您为什么将代码过于复杂化了这么多
    • 你到底为什么要使用频道来找到自己??
    猜你喜欢
    • 2021-01-18
    • 2022-01-16
    • 2021-05-04
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2022-01-26
    • 2019-01-29
    • 2021-09-27
    相关资源
    最近更新 更多