如何停止discord.py中的命令执行

时间:2020-10-22 01:34:53

标签: python discord.py discord.py-rewrite

如果用户余额<他所下注的钱,我试图停止执行命令。一切正常,但唯一的问题是,如果用户输入bet>他的余额,我将无法停止命令的执行。

我正在尝试停止执行 await message.channel.send(embed = error_bet_bal)

这是我的代码:

await message.channel.send(embed=discord.Embed(title='Please Enter The Amount to Bet', color=0xFFFF00))
        
        
        
        msg = await client.wait_for('message', check=check)
        bet_str = msg.content
        bet = int(bet_str)
        if bet>users_balance:
            await message.channel.send(embed = error_bet_bal) #displays that the users bal is less than what he is trying to bet. I am trying to stop it here but after displaying the error message it continues to the while loop.
       
while bet<1:
            if bet >= 1:
                break
            else:
                await message.channel.send(embed = error_bet)
                await message.channel.send(embed=discord.Embed(title='Please Enter The Amount to Bet', color=0xFFFF00))
                

                msg = await client.wait_for('message', check=check)
                bet_str = msg.content
                bet = int(bet_str)

非常感谢您:)

1 个答案:

答案 0 :(得分:1)

添加return以结束功能

下面是修改后的代码

await message.channel.send(embed=discord.Embed(title='Please Enter The Amount to Bet', color=0xFFFF00))
        
        
        
        msg = await client.wait_for('message', check=check)
        bet_str = msg.content
        bet = int(bet_str)
        if bet > users_balance:
            await message.channel.send(embed = error_bet_bal)
            return
     
       
while bet<1:
            if bet >= 1:
                break
            else:
                await message.channel.send(embed = error_bet)
                await message.channel.send(embed=discord.Embed(title='Please Enter The Amount to Bet', color=0xFFFF00))
                

                msg = await client.wait_for('message', check=check)
                bet_str = msg.content
                bet = int(bet_str)