G
G
Goshujin2021-03-25 21:13:51
Python
Goshujin, 2021-03-25 21:13:51

The bot issues 2 warn at once, how to fix it?

I wanted to make a very simple warning system, when entered into json, the bot immediately gives 2 warn, when repeated, it calculates normally. I ask to help with correction of duplication of the first warning.
The code:

@Bot.command()
async def warn(ctx, member: discord.Member, reason):
    mem = ctx.message.author
    if get(mem.roles, id = 824262219423678515):
        await ctx.message.delete()
        with open("D:\\UsersWarns.json", 'r') as f:
            warns = json.load(f)
        async def UserAdd_Warn1(warns, user):
            if not user in warns:
                warns[user] = {}
                warns[user]['User_Warns'] = 1
                emb = discord.Embed(title = f'{member.display_name}#{member.discriminator} Выдано предупреждение.', color = 0xff0000)
                emb.add_field(name="Модератор",value=ctx.message.author.mention,)
                emb.add_field(name="Пользователь",value=member.mention,)
                emb.add_field(name="Причина",value=reason,)
                emb.set_thumbnail(url="https://i.imgur.com/K2GwJCd.png")
                emb.set_footer(text = f"ID: {member.id}{ctx.message.created_at.strftime('[%d.%m.%Y %H:%M:%S]')}")
                await ctx.send(embed = emb)
        await UserAdd_Warn1(warns, str(member.id))
        async def UserAdd_Warns(warns, user, User_Warns):
            warns[user]['User_Warns'] += User_Warns
        await UserAdd_Warns(warns, str(member.id), 1)
        with open("D:\\UsersWarns.json", 'w') as f:
            json.dump(warns, f)
    
    else:
        pass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-25
@Goshujin

First they called the UserAdd_Warn1 function, which makes User_Warns = 1
Then they called the function, which makes User_Warns += 1
1+1=2
Solution? don't call the second function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question