如何使用 get_user_info 进行 Discord.py 重写
how to use get_user_info for 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."
victim_ID
是代表用户发送的消息的 Message
对象。您需要将该消息的内容提取为 int
:
msg = await self.bot.wait_for('message', check = is_correct)
victim_ID = int(msg.content)
所以,除了需要获取用户 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."
victim_ID
是代表用户发送的消息的 Message
对象。您需要将该消息的内容提取为 int
:
msg = await self.bot.wait_for('message', check = is_correct)
victim_ID = int(msg.content)