代码之家  ›  专栏  ›  技术社区  ›  user8442424

如何使Python Discord机器人模拟发送的所有消息?

  •  1
  • user8442424  · 技术社区  · 7 年前

    我正在使用Python(3.6.1版)编写一个Discord机器人。其功能之一是检测通道中发送的所有消息,对其进行处理,然后响应所述通道中的消息。(至少我是这么想的 希望 这是要做的。)

    我试过:

    @bot.event
    async def on_message(message):
        await bot.say(message.content)
    

    该函数在发送消息时响应,但不是以我希望的方式响应。相反,我得到了一个错误:

    discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType

    我该如何解决这个问题?非常感谢!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Community kavare    4 年前

    您不能使用 bot.say 在命令之外。

    我可以使用机器人吗。除了命令之外,在其他地方说什么?

    不。由于魔法的工作方式,它们只在命令内部工作。

    http://discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands

    要让bot重复发送的每条消息,可以使用 send_message . 下面是一个示例。

    @client.event
    async def on_message(message):
        await client.send_message(message.channel, message.content)