discord.py send_message用法

问题描述 投票:2回答:1

我已经开始研究一个项目来加速我对python的学习。我正在尝试重新创建一个不和谐的机器人我使用了很多,因为我已经习惯了它的功能。以下是我目前的代码

import discord
from discord import User
from discord.ext.commands import Bot

import secrets

pybot = Bot(command_prefix = "!")

@pybot.event
async def on_read():
    print("Client logged in")

@pybot.command()
async def hello(*args):
    print(User.display_name)
    return await pybot.say("Hello, world!")

@pybot.command()
async def truck(*args):
    await pybot.send_message(message.user,'Watchout for that truck!')

pybot.run(secrets.BOT_TOKEN)

我试图发生的事情是,当有人输入命令!truck <mention user>时,它会向该提到的用户发送一条消息,提示消息“注意那辆卡车!”。

我收到以下错误:

命令引发了异常:NameError:未定义名称“message”

我已经尝试查找我试图做但没有找到太多的例子,或者我不理解我应该做什么。希望这不是类似问题的转发

谢谢。

python discord discord.py
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.