C
C
Cyril Septimoor2020-12-27 21:15:15
Python
Cyril Septimoor, 2020-12-27 21:15:15

How to make a personal entry in a txt document and its subsequent output in a message?

I have a *profile command.
I want a server member to write their data
to it. The problem is to display personal data.
That is, when a person writes a command, it is necessary that it displays exactly his data that he indicated in the message, and not just all the data from txt

Here is the code:

# profile
@client.command(aliases = ['prof','profile','профиль'])
async def __profile(ctx, member: discord.Member):
    author = ctx.message.author
    now_date = datetime.datetime.now()
    file = open('profile.txt', encoding = 'utf-8')

    emb = discord.Embed(title = 'Профиль пользователя', color=0x20B2AA)
    emb.add_field(name="Вошёл на сервер:",value=member.joined_at, inline=False)
    emb.add_field(name='Псевдоним:',value=member.display_name, inline=False)
    emb.add_field(name = 'Время пользователя' , value = '{}'.format(now_date), inline=False)
    emb.add_field(name = 'День рождения' , value = f'{file.read()}', inline=False) # вывод данных
    emb.set_thumbnail(url=member.avatar_url)

    file.close()    
    await ctx.channel.purge(limit = 1)
    await ctx.send(embed = emb)
# edit profile
@client.command(aliases = ['eprof','editprofile','свояинфа'])
async def __eprofile(ctx, message):
    file = open('profile.txt', 'a', encoding = 'utf-8')
    file.write(f"\n{message}") # запись данных
    file.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-12-27
@poha_sep

Identify the user somehow, the script will not think out what information to give him. Use JSON

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question