【发布时间】:2021-08-02 14:55:16
【问题描述】:
当我在我的 discord 服务器上键入 $play 时,以下代码应该会运行,但当我运行它时没有任何反应..
client = commands.Bot(command_prefix='$')
@client.command(name="play")
async def play(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.message.channel and m.content.isdigit()
number = random.randint(1,100)
await ctx.send('I have a number in mind between 1 and 100, guess it')
for i in range(0,5):
guess = await client.wait_for("message", check=check)
if int(guess.content) > number:
await ctx.send("The number is greater")
elif int(guess.content) < number:
await ctx.send("The number is smaller")
elif int(guess.content) == number:
await ctx.send("You guessed the number!!.")
else:
return ("It has to be a positive integer between 1 to 100")
else:
await ctx.send("You lost, type $play to play again.")
【问题讨论】:
-
您是否导入了以下内容?
from discord.ext import commands -
@Dominik 我有;这是entirety of the code;猜谜游戏从第 45 行开始
-
你能更深入地解释发生了什么吗?当我复制你的代码时它工作正常,除了它总是告诉我输入 1000000 时数字更大
-
@loloToster 你输入
$play来运行代码了吗?当我在我的 Discord 服务器的频道上键入$play时,什么也没有发生。也没有错误。我记得当我弄乱代码时它确实运行了一次,同样的事情发生了;它总是表现得更好。 -
它显示得更大,因为你搞砸了
>和<标志它们应该被反转。关于不响应,您可以将print("test")放在play命令的顶部以检查它是否甚至响应$play?
标签: python discord discord.py