如何仅检测到小于某个数字的响应



我在discord bot上的赌博命令遇到了问题。我想知道如何只检测小于指定数字的响应。我试过一些东西。这是我的代码:

@client.command()
async def gamble(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.message.channel # New check



users = await get_bank_data()

user = ctx.author 
embed42=discord.Embed(title='I Have chosen a number between 1 and 1000', description='if you guesse under my number you get to keep the number u guessed but if you guessed over than you lose the money you geussed and if you geusse the exact number you get $10000!', color=0xbbe3f3)
await ctx.send(embed=embed42)
row = random.randint(1,1000)
response = await client.wait_for('message', check=check) # Wait for MESSAGE, add check
if response.content == row:
embed50 = discord.Embed(title='You Guessed ***on the dot***', description='You just got $10000')
await ctx.send(embed=embed50)
earniner = 10000
users[str(user.id)]["wallet"] += earniner
with open("mainbank.json","w") as f:
json.dump(users,f)
return True
if response.content == response >= row:
embed78 = discord.Embed(title='You Guessed **OVER**!', description=f'You just lost {ctx.message.content}')
await ctx.send(embed=embed78)
earninga = response
users[str(user.id)]["wallet"] -= earninga
with open("mainbank.json","w") as f:
json.dump(users,f)
return True
if response.content == response <= row:
embed78 = discord.Embed(title='You Guessed *under*!', description=f'You just got {ctx.message.content}')
await ctx.send(embed=embed78)
earninga = response
users[str(user.id)]["wallet"] += earninga
with open("mainbank.json","w") as f:
json.dump(users,f)
return True

正如我所说,我已经尝试了一些事情,但我就是想不通,希望有人能对我的问题发表一些看法。非常感谢。

您可以在check函数中执行此操作。出于某种原因,我还建议使用id而不是用户本人进行检查。

def check(m):
if m.author.id == ctx.author.id and m.channel.id == ctx.message.channel.id:
if m.content.isdigit(): #check message's content is a integer
if int(m.content) > 50: #checking the content is greater then 50
return True
return False

最新更新