【发布时间】: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
所以我正在创建一个命令来删除运行它的通道。 我的代码是这样的:
@client.command()
async def deletecurrent(ctx):
await ctx.send('Deleting..')
#Delete current channel code here
【问题讨论】:
标签: python python-3.x discord discord.py
我什至不会采取额外的步骤来通过 .get() 方法获取当前频道。
当前通道对象通过 ctx 对象传递给您。它包含 ctx.channel
所以删除当前频道的代码是:
await ctx.channel.delete()
【讨论】:
哦,我找到了方法!不是最好的解决方案,但在这里仍然有效:
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()。我不确定您为什么将代码过于复杂化了这么多