Search code examples
discorddiscord.py

(CLOSED) Bot doesnt send anything, and doesnt give an error


I have this code:

#rob
@client.command()
@commands.cooldown(1,10800,commands.BucketType.user)
async def rob(ctx,member:discord.User = None):
  if member == None:
    em = discord.Embed(title='ERROR:', description='Please specify a member you want to rob!', color=0xff0000)
  await ctx.send(embed = em) 
  return

  await open_account(ctx.author)
  await open_account(member)
    
  bal = await update_bank(member)

  if bal[0]<50:
    em = discord.Embed(title='ERROR:', description="The member you try to rob doesn't have that much money!", color=0xff0000)
  await ctx.send(embed = em) 
  return 
  
  if amount<0:
    em = discord.Embed(title='ERROR:', description="Amount must be positive!", color=0xff0000)
  await ctx.send(embed = em) 
  return 
    
  earnings = random.randrange(0, bal[100])
  fine = random.randrange(0, bal[100])

  em1 = discord.Embed(title='Succesfully robbed!', description=f"You robbed {earnings} coins!", color=0x00ff00)
  em2 = discord.Embed(title='Caught!', description=f"You got caught! You paid a {fine} coins fine! ", color=0x00ff00)

  yesorno = random.randrange(0, 1)
  if yesorno == 1:
      await ctx.send(embed = em1)
      await update_bank(ctx.author,earnings)
      await update_bank(member,-1*earnings)
  else:
      await ctx.send(embed = em2)
      await update_bank(ctx.author,-1*fine)

This function's goal is to rob someone and take their money or give them a fine, but it doesn't work. It doesn't send em1 or em2, I don't know how to fix it. I tried many things, but it doesn't give an error!


Solution

  • What fixed it for me was changing the yesorno function. Changed it to:

     yesorno = random.randrange(0, 2)
      if yesorno == 1:
        await ctx.send(embed = em1)
        await update_bank(ctx.author,1*earnings)
        await update_bank(member,-1*earnings)
      else:
        await ctx.send(embed = em2)
        await update_bank(ctx.author,-1*fine)
        await update_bank(member,1*fine)