如何使用get_user_info进行Discord.py重写

时间:2019-02-06 19:07:24

标签: python discord discord.py discord.py-rewrite

所以,我有一个可以运行的命令,除了需要获取用户ID的部分,这里是代码:

from discord import abc
from discord.ext import commands
import asyncio
class DMCog:
    def __init__(self, bot):
        self.bot = bot
    async def on_message(self, message):
        if message.guild is None:`

                if message.content.startswith("!report"):
                await message.channel.send("Who are you reporting? Input the ID only please.")

            def is_correct(m):
                return m.author == message.author and m.content.isdigit()

            victim_ID = await self.bot.wait_for('message', check = is_correct)
            victim = await self.bot.get_user_info(victim_ID)

            if victim == None:
                await message.channel.send("Can't find user, please try again")
                return
            else:
                success = (f"Found user: {victim.username} \n Is this correct? reply with Y or N. ")
                await message.channel.send(success)

它输出的错误:

"discord.errors.HTTPException: BAD REQUEST (status code: 400): Invalid Form Body
In user_id: Value "<Message id=542780755034767380 pinned=False author=<User id=197054540015599616 name='TheFutureKnight' discriminator='7664' bot=False>>" is not snowflake."

1 个答案:

答案 0 :(得分:0)

victim_IDMessage对象,代表用户发送的消息。您需要以int的形式提取该邮件的内容:

msg = await self.bot.wait_for('message', check = is_correct)
victim_ID = int(msg.content)