discord.py send_message用法 [英] discord.py send_message usage
问题描述
我已经开始研究一个项目,以加快我对python的学习。由于我已经习惯了它的功能,因此我试图重新创建一个我使用了很多的不和谐机器人。下面是我当前的代码
I've started working on a project to accelerate my learning of python. I'm trying to recreate a discord bot I use quite a bit since i'm already use to its features. Below is my current code
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>
时,它将消息发送给该用户消息小心那辆卡车!。
what im trying to get to happen is when someone types the command !truck <mention user>
it sends a message to that mentioned user with the message "Watch out for that truck!".
我遇到以下错误:
命令引发异常:NameError:未定义名称'message'
Command raised an exception: NameError: name 'message' is not defined
我尝试查找一些示例,这些示例说明了我正在尝试做的事情,但没有发现太多,或者不了解我应该做的事情。希望这不是类似问题的转贴
I've tried looking up examples of what im trying to do but haven't found much, or am not understanding what I should be doing. Hopefully this isn't a repost of a similar question
谢谢。
推荐答案
我相信卡车中的* args不再是有效的语法,对于带有discord.py的命令而言
The *args in your truck is no longer valid syntax I believe for the commands with discord.py
@pybot.command(pass_context=True)
async def truck(ctx):
await pybot.send_message(ctx.message.user, 'Watchout for that truck!')
使用示例
这篇关于discord.py send_message用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!