【发布时间】:2021-08-01 13:05:59
【问题描述】:
当$play 被输入到我的 Discord 服务器上的频道但机器人没有响应或以任何方式做出反应时,应该执行以下代码。
bot = commands.Bot(command_prefix='$')
@bot.command(name="play")
async def play(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.message.channel
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 bot.wait_for("message", check=check)
if guess.content > number:
await ctx.send("The number is greater")
elif guess.content < number:
await ctx.send("The number is smaller")
elif 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.")
【问题讨论】:
-
您的代码中有
on_message事件吗? -
@Chuaat 我应该在哪里(什么位置)添加
on_message事件? -
你不应该,
on_message事件与你的问题根本没有关系,你的代码有一个简单的逻辑错误。 -
这能回答你的问题吗? Guessing game, discord.py bot
标签: python discord discord.py