Hi I'm currently trying to make a bot with an Economy system for my Discord Bot using the MongoDB online service however I can't seem to get my code to work on using either the !balance or !work command as it keeps coming up with the following errors:
Errors:
2020-12-24T20:04:16.360587+00:00 app[worker.1]: Ignoring exception in command balance:
2020-12-24T20:04:16.362250+00:00 app[worker.1]: Traceback (most recent call last):
2020-12-24T20:04:16.362335+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped
2020-12-24T20:04:16.362336+00:00 app[worker.1]: ret = await coro(*args, **kwargs)
2020-12-24T20:04:16.362369+00:00 app[worker.1]: File "bot.py", line 43, in balance
2020-12-24T20:04:16.362369+00:00 app[worker.1]: await open_account(ctx.author)
2020-12-24T20:04:16.362445+00:00 app[worker.1]: File "bot.py", line 79, in open_account
2020-12-24T20:04:16.362447+00:00 app[worker.1]: discorduserid = ctx.author
2020-12-24T20:04:16.362498+00:00 app[worker.1]: AttributeError: 'Member' object has no attribute 'author'
Code:
@bot.command()
async def balance(ctx):
await open_account(ctx.author)
discorduserid = str(member.id)
results = collection.find({"userid":discorduserid})
for result in results:
wallet_amt = result["points"]
em = discord.Embed(title = f"{ctx.author.name}'s balance", colour = discord.Colour.red())
em.add_field(name = "Wallet", value = wallet_amt)
await ctx.send(embed = em)
@bot.command()
@commands.cooldown(1, 43200, commands.BucketType.user)
async def work(ctx):
await open_account(ctx.author)
discorduserid = ctx.message.author
earnings = random.randrange(500)
await ctx.send(f"You went to work and earned {earnings} coins!")
results = collection.update_many({"userid":discorduserid}, {"$inc":{"points":earnings}})
@work.error
async def work_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
timerem = str(timedelta(error.retry_after/28800)).split(".")[0]
msg1 = 'This command is on cooldown, please try again in '
msg2 = msg1 + timerem
await ctx.send(msg2)
else:
raise error
async def open_account(ctx):
discorduserid = ctx.author
if collection.find({"userid":discorduserid}):
return False
else:
newentry = {"userid":discorduserid, "points":0}
2020-12-25T01:19:42.580307+00:00 app[worker.1]: None 2020-12-25T01:19:42.580471+00:00 app[worker.1]: Ignoring exception in on_message 2020-12-25T01:19:42.582406+00:00 app[worker.1]: Traceback (most recent call last): 2020-12-25T01:19:42.582440+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped 2020-12-25T01:19:42.582440+00:00 app[worker.1]: ret = await coro(*args, **kwargs) 2020-12-25T01:19:42.582464+00:00 app[worker.1]: File "bot.py", line 57, in work 2020-12-25T01:19:42.582464+00:00 app[worker.1]: await open_account(ctx.author) 2020-12-25T01:19:42.582496+00:00 app[worker.1]: File "bot.py", line 91, in open_account 2020-12-25T01:19:42.582497+00:00 app[worker.1]: collection.insert_one(new_entry) 2020-12-25T01:19:42.582552+00:00 app[worker.1]: NameError: name 'new_entry' is not defined 2020-12-25T01:19:42.582599+00:00 app[worker.1]: 2020-12-25T01:19:42.582600+00:00 app[worker.1]: The above exception was the direct cause of the following exception: 2020-12-25T01:19:42.582600+00:00 app[worker.1]: 2020-12-25T01:19:42.582639+00:00 app[worker.1]: Traceback (most recent call last): 2020-12-25T01:19:42.582769+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 333, in _run_event 2020-12-25T01:19:42.582771+00:00 app[worker.1]: await coro(*args, **kwargs) 2020-12-25T01:19:42.582817+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 943, in on_message 2020-12-25T01:19:42.582817+00:00 app[worker.1]: await self.process_commands(message) 2020-12-25T01:19:42.582855+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 940, in process_commands 2020-12-25T01:19:42.582856+00:00 app[worker.1]: await self.invoke(ctx) 2020-12-25T01:19:42.582897+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 907, in invoke 2020-12-25T01:19:42.582897+00:00 app[worker.1]: await ctx.command.dispatch_error(ctx, exc) 2020-12-25T01:19:42.582932+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 424, in dispatch_error 2020-12-25T01:19:42.582932+00:00 app[worker.1]: await injected(ctx, error) 2020-12-25T01:19:42.582936+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 71, in wrapped 2020-12-25T01:19:42.582937+00:00 app[worker.1]: ret = await coro(*args, **kwargs) 2020-12-25T01:19:42.582976+00:00 app[worker.1]: File "bot.py", line 79, in work_error 2020-12-25T01:19:42.582977+00:00 app[worker.1]: raise error 2020-12-25T01:19:42.583009+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 903, in invoke 2020-12-25T01:19:42.583010+00:00 app[worker.1]: await ctx.command.invoke(ctx) 2020-12-25T01:19:42.583047+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 859, in invoke 2020-12-25T01:19:42.583047+00:00 app[worker.1]: await injected(*ctx.args, **ctx.kwargs) 2020-12-25T01:19:42.583076+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped 2020-12-25T01:19:42.583077+00:00 app[worker.1]: raise CommandInvokeError(exc) from exc 2020-12-25T01:19:42.583137+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'new_entry' is not defined 2020-12-25T01:19:44.629823+00:00 app[worker.1]: None 2020-12-25T01:19:44.630148+00:00 app[worker.1]: Ignoring exception in command balance: 2020-12-25T01:19:44.630460+00:00 app[worker.1]: Traceback (most recent call last): 2020-12-25T01:19:44.630523+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped 2020-12-25T01:19:44.630524+00:00 app[worker.1]: ret = await coro(*args, **kwargs) 2020-12-25T01:19:44.630556+00:00 app[worker.1]: File "bot.py", line 42, in balance 2020-12-25T01:19:44.630557+00:00 app[worker.1]: await open_account(ctx.author) 2020-12-25T01:19:44.630560+00:00 app[worker.1]: File "bot.py", line 91, in open_account 2020-12-25T01:19:44.630560+00:00 app[worker.1]: collection.insert_one(new_entry) 2020-12-25T01:19:44.630625+00:00 app[worker.1]: NameError: name 'new_entry' is not defined 2020-12-25T01:19:44.630677+00:00 app[worker.1]: 2020-12-25T01:19:44.630678+00:00 app[worker.1]: The above exception was the direct cause of the following exception: 2020-12-25T01:19:44.630678+00:00 app[worker.1]: 2020-12-25T01:19:44.630678+00:00 app[worker.1]: Traceback (most recent call last): 2020-12-25T01:19:44.630749+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 903, in invoke 2020-12-25T01:19:44.630749+00:00 app[worker.1]: await ctx.command.invoke(ctx) 2020-12-25T01:19:44.630753+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 859, in invoke 2020-12-25T01:19:44.630754+00:00 app[worker.1]: await injected(*ctx.args, **ctx.kwargs) 2020-12-25T01:19:44.630793+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped 2020-12-25T01:19:44.630794+00:00 app[worker.1]: raise CommandInvokeError(exc) from exc 2020-12-25T01:19:44.630843+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'new_entry' is not defined