Python 创建函数并通过message.channel.send发送

Python 创建函数并通过message.channel.send发送,python,discord.py,Python,Discord.py,试图从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 o

试图从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")
来自discord.ext导入命令
bot=discord.ext.commands.bot(命令前缀=“$”)
#功能
异步def gamesAwayb1():
返回153-on_消息()
#不确定要放什么而不是放在信息上
@机器人事件
异步def on_消息(消息):
如果0
忽略on_消息中的异常 回溯(最近一次呼叫最后一次): 文件“/opt/virtualenvs/python3/lib/python3.8/site packages/discord/client.py”,第343行,在运行事件中 等待coro(*args,**kwargs) on_消息中第13行的文件“main.py” 等待消息。频道。发送(“你在青铜1中。你在”,gamesAwayb1(消息),“远离青铜2的游戏”)
TypeError:gamesAwayb1()接受0个位置参数,但给出了1个

也许您可以创建一个简单的函数

def gamesAwayb1(num):
    return 153 - int(num) # to convert string to num
并从
message.content
传递号码,当触发
on\u message
时,如下所示:,
gamesAwayb1(message.content)

或者你不需要函数,如果你只需要

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)))
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")
async def on_消息(消息):
如果0
如果要检查输入中是否有有效数字,可以尝试以下操作:

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)))
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")
async def on_消息(消息):
尝试:
如果0
感谢您的回答,但我收到一条很长的错误消息,忽略了on_message Traceback(最近一次调用)中的异常:文件“/opt/virtualenvs/python3/lib/python3.8/site packages/discord/client.py”,第343行,在运行事件等待coro(*args,**kwargs)文件“main.py”,第10行,在on_message wait message wait message.channel.send中(“you is in Bronze 1.you is”,153-int(message.content),“games About from Bronze 2”)类型错误:send()接受1到2个位置参数,但在on_message Traceback(最近一次调用)中忽略了4个异常:File“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py,第343行,_run_事件中的wait coro(*args,**kwargs)文件“main.py”,第9行,如果0