0
votes

Trying to subtract the number sent in a message from 153

from discord.ext import commands

bot = discord.ext.commands.Bot(command_prefix = "$")

#the function
async def gamesAwayb1():
 return 153 - on_message() 
#not sure what to put instead of on_message

@bot.event

async def on_message(message):
  if 0 < int(message.content) < 153:
   await message.channel.send("you are in Bronze 1.  You are" , gamesAwayb1() , "games away from Bronze 2")


  if 153 < int(message.content) < 200:
   await message.channel.send("you are in Bronze 2")

Ignoring exception in on_message Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event await coro(*args, **kwargs) File "main.py", line 13, in on_message await message.channel.send("you are in Bronze 1. You are" , gamesAwayb1(message) , "games away from Bronze 2") TypeError: gamesAwayb1() takes 0 positional arguments but 1 was given

1

1 Answers

0
votes

Perhaps you can create a simple function,

def gamesAwayb1(num):
    return 153 - int(num) # to convert string to num

And pass the number from message.content when on_message is triggered like, gamesAwayb1(message.content).

Or you wouldn't need a function if you would just do something like,

async def on_message(message):
    if 0 < int(message.content) < 153:
        await message.channel.send("you are in Bronze 1.  You are {} games away from Bronze 2".format(153 - int(message.content)))

If you want to check if valid number is in the input, you can try something like,

async def on_message(message):
    try:
        if 0 < int(message.content) < 153:
            await message.channel.send("you are in Bronze 1.  You are {} games away from Bronze 2".format(153 - int(message.content)))
    except ValueError:
        await message.channel.send("Please enter valid number")