How to make a discord.py bot private/direct message someone who#39;s not the author?(如何使 discord.py 机器人私人/直接消息不是作者的人?)
问题描述
假设我想制作一个具有poke"功能的机器人(也就是当有人说!poke @user#0000"时向用户发送一个说Boop"的 pm),我该怎么做?当我这样做时效果很好:
Say I want to make a bot with a "poke" feature (aka sends a pm to a user saying "Boop" when someone says "!poke @user#0000"), how would I do this? It works perfectly when I do this:
@bot.command(pass_context=True)
async def poke(ctx, message):
await client.send_message(ctx.message.author, 'boop')
但前提是我想戳消息的作者.我想戳那些被@'d 的人.
but only if I want to poke the author of the message. I want to poke whoever's being @'d.
我知道 discord.py 文件说我可以使用这个:
I know the discord.py documents say I can use this:
start_private_message(user)
但我不知道用什么代替用户.
but I don't know what to put in place of user.
推荐答案
其实比那个简单
@bot.command(pass_context=True)
async def poke(ctx, member: discord.Member):
await bot.send_message(member, 'boop')
send_message
包含私人消息的逻辑,因此您不必自己使用 start_private_message
.: discord.Member
称为转换器,描述为 在此处的文档中
send_message
contains logic for private messages, so you don't have to use start_private_message
yourself. The : discord.Member
is called a converter, and is described in the documentation here
这篇关于如何使 discord.py 机器人私人/直接消息不是作者的人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 discord.py 机器人私人/直接消息不是作者的人?


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