【问题标题】:getting an error when i try to request the bot当我尝试请求机器人时出现错误
【发布时间】:2021-05-18 16:10:17
【问题描述】:

好的,所以我在 repl.it 上使用 python 构建了一个不和谐机器人 问题是我的机器人甚至显示它在线但是每当我输入 $hello 它只会在我脸上抛出一个大错误 This is the photo of my code and the error

import os
import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('TOKEN')

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@client.event
async def on_message(message):

  if message.author == client.user:
    return

  if message.content.startswith('$hello'):
    await message.send.channel('Hello there young shona follower!')

client.run(TOKEN)

这就是错误

忽略 on_message Traceback 中的异常(最近一次调用最后一次):
文件 “/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py”, 第 343 行,在 _run_event await coro(*args, **kwargs) 文件“main.py”,第 21 行,on_message await message.send.channel('Hello there young shona follower!') AttributeError: 'Message' object has no attribute 'send'

【问题讨论】:

    标签: python discord


    【解决方案1】:

    这是message.channel.send,而不是message.send.channel

    await message.channel.send('Hello there young shona follower!')
    

    【讨论】:

      【解决方案2】:

      错误是不言自明的。您不能在 on_message 函数中对 message 对象调用 send 方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-11
        • 1970-01-01
        • 2011-09-03
        • 1970-01-01
        • 2021-07-09
        • 1970-01-01
        • 2020-12-07
        • 2018-07-21
        相关资源
        最近更新 更多