discord.py send_message usage(discord.py send_message 用法)
问题描述
我已经开始着手一个项目来加速我对 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: name 'message' is not defined
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 的 github 存储库例子
这篇关于discord.py send_message 用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:discord.py send_message 用法


基础教程推荐
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01