Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question