Answer the question
In order to leave comments, you need to log in
How to get the Member object knowing the id?
I want to make a !info command that will show the date the account was created, from the phone / from the PC and (what just doesn’t work) the date of entering the server
@client.command(pass_context = True)
async def info(ctx):
args = ctx.message.content.lstrip('{}info '.format(config.get('config.prefix')))
if len(args) > 0:
try:
print(int(args.split('<@')[1].split('>')[0]))
user = await client.fetch_user(int(args.split('<@')[1].split('>')[0]))
member = await Guild.fetch_member(int(args.split('<@')[1].split('>')[0])) # Вот как я сделал
emb = discord.Embed(
title = f'Информация о {user.name}',
colour = discord.Colour.from_rgb(
color_neutral[0],
color_neutral[1],
color_neutral[2]),
timestamp = ctx.message.created_at)
emb.add_field(name = 'Дата создания аккаунта:', value = str(user.created_at).split(' ')[0], inline = True)
emb.add_field(name = 'Дата входа на сервер:', value = str(member.joined_at).split(' ')[0], inline = True)
if member.is_on_mobile():
emb.add_field(name = 'С телефона', value = str(' '), inline = True)
else:
emb.add_field(name = 'С пк', value = str(' '), inline = True)
emb.set_thumbnail(url=user.avatar_url)
await ctx.send(
embed = emb,
delete_after=float(config.get('config.time_before_delete'))
)
except:
await ctx.send(
embed = discord.Embed(
title = f'Ошибка',
colour = discord.Colour.from_rgb(
color_negative[0],
color_negative[1],
color_negative[2]),
timestamp = ctx.message.created_at),
delete_after=float(config.get('config.time_before_delete')))
else:
print(ctx.message.author.id)
user = await client.fetch_user(ctx.message.author.id)
member = await Guild.fetch_member(ctx.message.author.id) # Нуу это тоже самое
emb = discord.Embed(
title = f'Информация о {ctx.message.author.name}',
colour = discord.Colour.from_rgb(
color_neutral[0],
color_neutral[1],
color_neutral[2]),
timestamp = ctx.message.created_at)
emb.add_field(name = 'Дата создания аккаунта:', value = str(user.created_at).split(' ')[0], inline = True)
emb.add_field(name = 'Дата входа на сервер:', value = str(member.joined_at).split(' ')[0], inline = True)
if member.is_on_mobile():
emb.add_field(name = 'С телефона', value = str(' '), inline = True)
else:
emb.add_field(name = 'С пк', value = str(' '), inline = True)
emb.set_thumbnail(url=ctx.message.author.avatar_url)
await ctx.send(
embed = emb,
delete_after=float(
config.get('config.time_before_delete')
)
)
624301440973668352
Ignoring exception in command info:
Traceback (most recent call last):
File "C:\Users\ \AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "D:\ \ \ \bot.py", line 789, in info
member = await Guild.fetch_member(ctx.message.author.id)
TypeError: fetch_member() missing 1 required positional argument: 'member_id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Максим\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Максим\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Максим\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: fetch_member() missing 1 required positional argument: 'member_id'
member = await Guild.fetch_member(ctx.message.author.id)
Answer the question
In order to leave comments, you need to log in
Help on function fetch_member in module discord.guild:
async fetch_member(self, member_id)
class Horse: # тип - лошадь
...
def send_to_space(self, encapsulate: bool):
# Функция позволяющая отправить лошадь в космос
self.move(Place("Space"))
special_horse_in_vacuum = Horse(...) # Один определенный сферический конь
special_horse_in_vacuum.send_to_space(True) # Отправляем определенного коня в вакуум
special_horse_in_vacuum = Horse # Определение лошади
special_horse_in_vacuum.send_to_space(True) # Пытаемся отправить определение "лошадь" в космос
# Получаем TypeError: send_to_space() missing 1 required positional argument: 'encapsulate'
@bot.command()
async def test(ctx, member_id: int):
print(await ctx.guild.fetch_member(member_id)) # Получить пользователя через API
print(ctx.guild.get_member(member_id)) # Получить пользователя из кэша бота
@bot.command()
async def info(ctx, *, member: discord.Member):
await ctx.send(f"Вас называют: {member.display_name}. Ваш ID: {member.id}. etc...")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question