【问题标题】:How to make the bot speak on another channel? (with discord.py)如何让机器人在另一个频道上讲话? (与不和谐.py)
【发布时间】:2018-07-07 00:10:36
【问题描述】:

我希望我的机器人向某个频道发送消息,(但我没有输入 id,因为我的机器人将是公开的) 我使用了这个命令:

await client.send_message(destination=teste, content='oi (hello)')

但它不会产生任何结果并给出以下错误:

Ignoring exception in on_message
Traceback (most recent call last):
  File "PycharmProjects\LennieBot\venv\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "PycharmProjects/LennieBot/main.py", line 42, in on_message
    if message.content.lower().startswith((prefix) + 'botavatar'):
NameError: name 'teste' is not defined

有人可以帮助我(不要用另一种语言称呼这些词,我是葡萄牙语 c:)

【问题讨论】:

  • 我从我的用户 (c:users) 那里获取了路径
  • 你能验证是否定义了teste

标签: python discord discord.py


【解决方案1】:

您可能没有定义变量“teste”。假设您要将消息发送到服务器频道,您必须先获取该频道:

teste = client.get_channel(“id”)

其中“id”是您要发送消息的频道 ID。请注意,这必须是字符串,而不是整数。

【讨论】:

    猜你喜欢
    • 2020-12-28
    • 2021-08-13
    • 2021-07-07
    • 2020-10-15
    • 2019-11-05
    • 2019-06-24
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多