【问题标题】:How to make my Discord bot send a message to the chat [duplicate]如何让我的 Discord 机器人向聊天室发送消息 [重复]
【发布时间】:2019-11-06 23:44:45
【问题描述】:

我想做一些简单的聊天命令。我在网上搜索了一些,但我没有找到任何可以理解的内容

import discord



client = discord.Client()

@client.event
async def on_ready():
    print("THE SHEEP BOT IS HERE!")
    await client.change_presence(activity=discord.Game("a bot"))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content == "Hey":
        await client.send_message(message.channel, "Hey.")

client.run("MYTOKEN")

目前,机器人的状态为“A bot”,这很好,我让它这样做了,就在我作为不和谐类型的用户时,机器人什么也不做。

我在运行程序时也遇到此错误

    await client.send_message(message.channel, "Hey.")
AttributeError: 'Client' object has no attribute 'send_message'

【问题讨论】:

  • 确实做某事,它试图发送一条消息,但它不能,因为该方法不存在on Client
  • client.send_message 在迁移后被弃用

标签: python discord discord.py


【解决方案1】:

不要使用send_message,而是尝试message.channel.send

例如:

await message.channel.send("Hey.")

顺便说一句,send_message 不起作用的原因是因为它使用了不推荐使用的 discord.py 的异步版本。 Here's the github issue.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2019-09-19
    • 2018-04-07
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多