如何停止我的discord bot的if语句

2024-04-19 05:13:24 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想做一个数字猜谜游戏discord机器人。一切正常,直到它到达终点(我希望它停止)。我意识到,即使代码结束了,机器人仍然在接受我说的话。我有没有办法阻止这一切的发生

(我才15岁,是python的新手,所以请耐心等待。) 这是我的密码:)

import keep_alive
import discord
import os
from discord.ext import commands
import random
import sys


number = random.randint(1, 100)
client = commands.Bot(command_prefix=".")


@client.event
async def on_ready():
  print("The bot is online")



@client.command()
async def numpuz(ctx):
  await ctx.send("Type a starting number")
 
  @client.command()
  async def num(ctx, chosennumber):
    if chosennumber > str(number):
      await ctx.send('number too high, pick a smaller one')
          
    if chosennumber < str(number):
      await ctx.send('number too small, pick a bigger one')
        
    if chosennumber == str(number):
      await ctx.send('YOU WON')
      
          
keep_alive.keep_alive()
client.run(os.getenv("token"))