【发布时间】:2021-01-14 20:41:45
【问题描述】:
@client.event
async def on_message(message):
print(message.author.bot)
content = message.content
author = message.author
print("{}: {}".format(author, content))
if message.content.startswith(".play"):
import random
words = [
"expert",
"error",
"fairies",
"star",
"example",
"pencil",
"friction",
"attraction",
"horse",
"vegetable",
"stove",
"invention"]
word = random.choice(words)
guesses = 7
hint = ""
i = 0
try:
await message.channel.send("Guess the word!")
while guesses > 0:
user_input = await client.wait_for('message', timeout=60.0, check=None)
user_input = message.content
print(user_input)
if user_input == word:
await message.channel.send("You found the word!")
elif user_input != word:
await message.channel.send("Guessed wrong!")
try:
hint += word[i]
except IndexError:
break
i += 1
await message.channel.send(f"Here is hint {hint}")
guesses -= 1
await message.channel.send(f"{guesses} left")
if guesses == 0:
break
except asyncio.TimeoutError:
await message.channel.send("Time out!")
我试图用 python 将我的猜谜游戏集成到 discord bot 中,但它是这样的:
** ????????????_???????????????????_??????0????#1885:.play
??????????????????????????????#8974:猜字!
????????????_?????????????????????_????0??????#1885: 测试
??????????????????????????????#8974:猜错了!
??????????????????????????????#8974: 这是提示e
??????????????????????????????#8974:还剩6个
????????????_?????????????????????_????0????#1885:专家
??????????????????????????????#8974:猜错了!
??????????????????????????????#8974: 这里是提示
??????????????????????????????#8974:还剩5个
????????????_?????????????????????_????0????#1885:额外
??????????????????????????????#8974:猜错了!
??????????????????????????????#8974: 这里是提示exa
??????????????????????????????#8974:还剩4个
????????????_?????????????????????_??????0????#1885: 例子
??????????????????????????????#8974:猜错了!
??????????????????????????????#8974: 这是提示考试
??????????????????????????????#8974:还剩3个
????????????_?????????????????????_????0??????#1885: asd
??????????????????????????????#8974:猜错了!
??????????????????????????????#8974: 这是提示示例
??????????????????????????????#8974: 2 left
** 如您所见,消息卡在“.play”处。 (我调试了它)问题是我不知道如何重置消息并接收另一个输入。
【问题讨论】:
标签: python discord.py discord.py-rewrite