【发布时间】:2021-05-17 16:26:06
【问题描述】:
更新
由于某种原因,尽管我的代码看似正确,但我的 discord 机器人无法响应多条消息。此外,我在 VS Code 中遇到了一个问题:除非我关闭、重新打开编辑器并重新运行代码,否则终端不会更新!请记住,除非程序在终端上显示“就绪”,否则不和谐机器人不会运行。由于那个终端问题,我的机器人运行不完美! 那么什么会导致这样的问题呢?
注意:
当我点击运行按钮是 VSC 时,没有任何变化。(除非我重新打开编辑器,否则它不起作用)
...
@bot.event
async def on_message(message):
events = ['happy birthday', 'joyeux anniversaire']
games = ['rocket league', 'Minecraft']
while True:
if message.author == bot.user:
return
for event in events:
if event in message.content.lower():
await message.channel.send('Happy Birthday! ????????')
for game in games:
if game in message.content.lower():
await message.channel.send('It\'s play time ! ')
...
【问题讨论】:
-
使用
if 'rocket league' in message.content.lower(): ...有什么问题?这是python的基础知识 -
甚至
for text in games: if text in message.content.lower(): ...?这是Python的基础知识 -
@furas 我知道这真的很简单。我尝试了多次,但由于某种原因它不起作用。但是,在我关闭并重新打开编辑器后,它现在可以正常工作了!
-
也许您有两个文件 - 也许您在一个文件中进行了更改,但它一直在运行其他文件。或者,也许您在更改后没有重新启动机器人,而您一直在运行旧代码。
标签: python discord discord.py