gpt4 book ai didi

python - 如何使 discord.py bot 成为非作者的私有(private)/直接消息?

转载 作者:太空宇宙 更新时间:2023-11-04 00:21:02 25 4
gpt4 key购买 nike

假设我想制作一个具有“戳”功能的机器人(也就是当有人说“!戳@user#0000”时向用户发送一条消息说“Boop”),我该怎么做?当我这样做时它完美地工作:

@bot.command(pass_context=True)
async def poke(ctx, message):
await client.send_message(ctx.message.author, 'boop')

但前提是我想戳消息的作者。我想戳戳被@'d 的人。

我知道 discord.py 文档说我可以使用这个:

start_private_message(user)

但我不知道用什么代替用户。

最佳答案

其实比那更简单

@bot.command(pass_context=True)
async def poke(ctx, member: discord.Member):
await bot.send_message(member, 'boop')

send_message 包含私有(private)消息的逻辑,因此您不必自己使用 start_private_message: discord.Member 称为转换器,描述为 in the documentation here

关于python - 如何使 discord.py bot 成为非作者的私有(private)/直接消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49098057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com