R
R
Romeo5582022-04-01 23:52:08
Python
Romeo558, 2022-04-01 23:52:08

How to get basic user data in discord?

I just started making my new Discord bot today. I keep a log.
Problem: I can't get the sender of a message (no matter what). That is, who where and at what time sent a message or link. The structure of my code looks something like this:

@bot.command() #Метод для каждой команды для бота
async def start_message(ctx): #Приветственное сообщение
    author = ctx.message.author
    await ctx.send(f'{author.mention}, привет!') #Здесь я могу получить имя пользователя, но вне функции я этого сделать не могу, именно в этом проблема.
@bot.command()
async def hello_message(ctx):#Ещё команда
    author = ctx.message.author
    embed = discord.Embed(color=654321, title=f'Привет, {author}!!') #Эмбед сообщение
    embed.set_image(url='https://avatars.mds.yandex.net/get-pdb/1390202/3d87c5f7-dbe3-46db-b73e-a1c59ca88e37/s1200')
    await ctx.send(embed = embed)
@bot.command()
async def ilovemyfamily(ctx):
    embed = discord.Embed(color=654321, title=f'Хабр топ')
    embed.set_image(url='https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Heart_coraz%C3%B3n.svg/800px-Heart_coraz%C3%B3n.svg.png')
    await ctx.send(embed = embed)

Question: How can I get the user's name, ID(#????), an arbitrary nickname on the server, and finally the text of the message outside of the function?
I will use the with open method, and that's it, but I just need to keep a journal.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ex2mple, 2022-04-02
@Romeo558

@bot.listen()
async def on_message(message):
    member = message.author
    name = member.name
    discriminator = member.discriminator #Это непосредственно ID(#????) - четыре цифры на конце имени
    nick = member.nick
    text = message
    # далее записываете переменные туда, куда вам нужно

In general, read the documentation - https://discordpy.readthedocs.io/en/stable/index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question