本文介绍了如何获取参数以忽略消息的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道如何获取if语句( if 0< int(message.content)< 153:
)来仅测试部分消息,而不是完整的message.content.例如:如果我输入 1s 100
,我希望它测试是否只有100,并且忽略 1s
,但还必须使消息以 1秒
I just wondering how to get the if statement(if 0 < int(message.content)< 153:
) to only test part of the message, not the full message.content.Eg: if I put in 1s 100
, I want it to test if ONLY the 100 is within and ignore the 1s
, but also have to have the message start with 1s
import discord
from discord.ext import commands
from math import floor
import math
from keep_alive import keep_alive
bot = discord.ext.commands.Bot(command_prefix = "$")
@bot.event
async def on_message(message):
if message.author.bot:
return
if 0 < int(message.content) < 153 & message.content.startswith('1s') :
await message.channel.send("you are in Bronze 1. You are about {} games away from Bronze 2. *I am not always correct*".format(math.floor((153 - int(message.content))/8 + 1)))
推荐答案
您只需将 [3:]
添加到 message.content
: 0<int(message.content [3:])<153
.仅当消息以数字开头的3位数字开头(在您的情况下为 1s
)
You can just simply add [3:]
to message.content
:0 < int(message.content[3:]) < 153
. This only works if the message starts with 3 figures before the number (in your case it's 1s
)
这篇关于如何获取参数以忽略消息的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!