Im programing a Discord bot and and have some functions depending on the method. I have one bot.event that search for all messages and apply its function, and one bot command that only search for the command !balance and apply its function. The problem is that the bot.command is not working as the method on_message is acting first. How can I write that on the method on message the program exclude the commands??
@bot.event
async def on_message(ctx):
await open_account(ctx.author)
users = await get_bank_data()
user = ctx.author
earnings_1 = 1
users[str(user.id)]['wallet'] += earnings_1
with open('bank.json', 'w') as f:
json.dump(users, f)
@bot.command(pass_context=True)
async def balance(ctx):
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
wallet_amt = users[str(user.id)]['wallet']
em = discord.Embed(
title = f"{ctx.author.name}´s balance:",
color = 0xf3e577
)
em.add_field(name = 'Wallet Balance', value = wallet_amt)
await ctx.send(embed = em)
async def open_account(user):
users = await get_bank_data()
if str(user.id) in users:
return False
else:
users[str(user.id)]= {}
users[str(user.id)]['wallet'] = 0
users[str(user.id)]['bank'] = 0
with open('bank.json', 'w') as f:
json.dump(users, f)
return True
async def get_bank_data():
with open('bank.json','r') as f:
users = json.load(f)
return users
should I use other method?