Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从discord.py rewrite发送pm_Python_Python 3.x_Discord_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 从discord.py rewrite发送pm

Python 从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

我想知道如何从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 (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