我已经开始致力于一个项目来加速我对 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:名称“消息”未定义
我尝试查找我想做的事情的例子,但没有找到太多,或者不明白我应该做什么。希望这不是类似问题的转发
Thanks.
我相信卡车中的 *args 对于带有discord.py的命令不再是有效的语法
@pybot.command(pass_context=True)
async def truck(ctx):
await pybot.send_message(ctx.message.user, 'Watchout for that truck!')
查看 Discord.py 的 github 存储库及其examples https://github.com/Rapptz/discord.py/tree/async/examples
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)