我已经开始着手一个项目来加速我对 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: name 'message' is not defined
我已经尝试查找我正在尝试做的事情的示例,但没有找到太多,或者我不明白我应该做什么。希望这不是类似问题的转贴
谢谢。