Python 从discord.py rewrite发送pm
我想知道如何从discord.py重写机器人发送pm。我无法执行ctx.author.send(“上下文”),因为它会向消息作者以外的其他人发送消息。 这是我到目前为止在搜索用户时得到的代码,它的值总是为NONEPython 从discord.py rewrite发送pm,python,python-3.x,discord,discord.py,discord.py-rewrite,Python,Python 3.x,Discord,Discord.py,Discord.py Rewrite,我想知道如何从discord.py重写机器人发送pm。我无法执行ctx.author.send(“上下文”),因为它会向消息作者以外的其他人发送消息。 这是我到目前为止在搜索用户时得到的代码,它的值总是为NONE @bot.command() async def spam(ctx, author, message, amount): print(author) print(ctx.author) victim = bot.get_user(author) print(victim) if not
@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
您可以使用自动解析受害者的用户
对象
@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