【问题标题】:discord bot python delete channel gives an errordiscord bot python删除通道出错
【发布时间】:2021-09-08 06:04:34
【问题描述】:

我试图发出一个命令来删除针对 nuke bot 的 nuke 频道, 这是我的代码:

async def inferno(ctx,problem):
    if problem == ("channelnuke"):
        channel == ("Nuke-channel")
        await ctx.send("okay solving problem")
        await ctx.send("Guard on, every nuke channel will be instant deleted")
        while True:
            
            await channel.delete()

但它给出了一个错误,即不和谐没有属性删除

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord.channel' has no attribute 'delete'

有人知道应该怎么做吗?

【问题讨论】:

  • while 循环的目的是什么?

标签: python discord command discord.py bots


【解决方案1】:

很遗憾,由于我的声誉不足,我无法对上一个答案发表评论。所以这是上一个答案的更新代码,现在应该可以工作了。

@client.command()
async def inferno(ctx, problem):
    if problem == "channelnuke":
        channel = ctx.channel   # the previous answer had put (==) instead of (=)
        await ctx.send("okay solving problem")
        await ctx.send("Guard on, every nuke channel will be instant deleted")
        await channel.delete()

如果你想添加频道,你可以通过将频道作为可选参数来实现:

@client.command()
async def inferno(ctx, problem, channel : commands.TextChannelConverter = None): # we will put the channel into an optional arguments by doing = None
    if channel == None: # it will find the channel if you didn't specify the channel
        channel = ctx.channel
    await ctx.send("okay solving problem")
    if problem == "channelnuke":
        await channel.delete()

TextChannelConverter 将查看频道,您可以使用 id、频道名称或提及频道,它应该可以工作,有关它的更多信息将在下面。

TextChannelConverter Docs

稍后谢谢我:D

【讨论】:

  • 谢谢 Pixie,你也知道如何指定频道名称吗?
  • 我现在添加了命令,它应该可以工作 :D,看看我编辑的答案
  • 谢谢,我怎么做这个循环?
【解决方案2】:
async def inferno(ctx, problem):
    if problem == "channelnuke":
        channel == ctx.channel
        await channel.delete()
        await ctx.send("okay solving problem")
        await ctx.send("Guard on, every nuke channel will be instant deleted")

【讨论】:

  • 这不起作用仍然给出一些错误
猜你喜欢
  • 1970-01-01
  • 2021-01-28
  • 2020-08-25
  • 2020-12-27
  • 2020-10-01
  • 1970-01-01
  • 2020-12-04
  • 2021-04-29
  • 2020-08-25
相关资源
最近更新 更多