Send a pm from discord.py rewrite

假如想象 提交于 2019-12-11 10:48:05

问题


I'm trying to figure out how to send a pm from a discord.py rewrite bot. I can't do ctx.author.send("context") because it messaging someone other than the author of the message. here's the code that I have so far when I'm searching for a user it always comes with the value of 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")

It has the out put of

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

回答1:


You can use a converter to resolve the User object of your victim automatically.

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

You can then use their name, id, or a mention to specify them:

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


来源:https://stackoverflow.com/questions/51978648/send-a-pm-from-discord-py-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!