K
K
Killir Vanya2292021-07-16 21:28:36
Python
Killir Vanya229, 2021-07-16 21:28:36

How to fix 2 errors?

I'm making a mini data dumper from a command on a txt file
, and here I have 2 problems:
1. when the bot is restarted, all statistics that are reset in .txt
2. an error is displayed when you want to check member info

member = ctx.member.id or ctx.author.id
AttributeError: 'Context' object has no attribute 'member'


@bot.command()
async def year(ctx, *, msg):
    bot.year[ctx.member.id] = [ctx.message.id, msg]

    async with aiofiles.open("year.txt", mode="r") as file:
        data = await file.readlines()

    async with aiofiles.open("year.txt", mode="w") as file:
        await file.write(f"{ctx.author.id} {ctx.message.id} {msg}\n")

        for line in data:
            if int(line.split(" ")[0]) != ctx.member.id:
                await file.write(line)

    await ctx.send(f"**Теперь в !check будет отображаться** {msg}")

@bot.command()
async def check(ctx, member: discord.Member = None):
    member = ctx.member.id or ctx.author.id
    try:
        ctx.message.id, msg = bot.year[member]
    except KeyError:
        await ctx.channel.send("Неизвестно")
    else:
        await ctx.send(f'{msg}')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Mokhovikov, 2021-07-16
@mohovoy

I don’t know about the text, but the 2nd mistake is clear. Member does not have a ctx parameter. If I'm not mistaken it should look like this:
member = member.id or ctx.author.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question