gpt4 book ai didi

python - 从discord.py rewrite 发送一个pm

转载 作者:行者123 更新时间:2023-12-01 09:06:45 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何从discord.py重写机器人发送下午消息。我无法执行 ctx.author.send("context") 因为它向消息作者以外的其他人发送消息。这是到目前为止我在搜索用户时所拥有的代码,它总是带有 NONE 值

@bot.command()
async def spam(ctx, author, message, amount):
print(author)
print(ctx.author)
victim = bot.get_user(author)
print(victim)
if not (victim == None):
for i in range(int(amount)):
await victim.send(message)
else:
print("NOPE")

它的输出为

GIMMY READY......
Denard#0759
Denard#0759
None
NOPE

最佳答案

您可以使用 converter自动解析您的受害者User对象。

@bot.command()
async def spam(ctx, victim: discord.User, amount, *, message):
for _ in range(amount):
await victim.send(message)

然后您可以使用他们的姓名、ID 或提及来指定他们:

!spam Denard 1 spam spam spam
!spam @Denard 1 spam spam spam
!spam 1234 1 spam spam spam

关于python - 从discord.py rewrite 发送一个pm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51978648/

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