【问题标题】:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Events' object has no attribute 'get_channeldiscord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“事件”对象没有属性“get_channel”
【发布时间】:2022-01-05 21:13:08
【问题描述】:

我想让它在我的机器人启动时向某些聊天发送消息。正常上电,一切都很好,当我已经使用特殊的重启命令时,就会发出这个错误。代码如下:

@client.event
async def on_ready():
    changeStatus.start()
    kvuqqs = client.get_channel(906998823187017728)
    librar = client.get_channel(906168716197232660)

    await kvuqqs.send('Айоу! Бот был включен. \nК сожалению, на данный момент обновлений нет. \n`l.хелп`')
    await librar.send(embed=discord.Embed(title='Бот был включен!', description='Версия бота на данный момент: 2.0.1.', color=random.choice(colors)))

还有一个完整的错误:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Events' object has no attribute 'get_channel'

【问题讨论】:

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


    【解决方案1】:

    布鲁 要从 id 获取频道,您需要一个公会

    示例:-

    guild = client.get_guild(ID)
    channel = guild.get_channel(ID)
    

    通过 id 获取频道或公会是特权意图

    在您的机器人中添加此代码(如果您没有)

    intents = discord.Intents().all()
    client = commands.Bot(command_prefix='prefix', intents=intents)
    

    您必须在 Discord Dev Portal 中打开这些意图

    您可以在此处阅读有关意图的更多信息:- https://discordpy.readthedocs.io/en/stable/intents.html

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 2021-12-07
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 2021-12-04
      • 2021-07-18
      相关资源
      最近更新 更多