【发布时间】:2021-12-24 20:31:15
【问题描述】:
我一直致力于使用 python 制作一个不和谐的机器人。
我输入了random.choice 以从列表flirt 中获取消息。此外,该函数需要读取列表中的特定单词sad,然后响应flirt。
这是我的python代码:
async def on_message(message):
if message.author == client.user:
return
for word in sad:
if word in message.content:
response = random.choice(flirt)
await message.reply(response)
break
两个列表示例:
sad = ["sad", "depressed", "lonely", "miserable"]
flirt = ["Baby I will be the broom that sweeps all the sadness in your heart.", "If a star would cure sadness, your heart would be empty of sadness."]
【问题讨论】:
-
奇怪。 1/
random.choice不起作用是什么意思?脚本挂了吗?函数什么都不返回吗?还是一个空字符串?等 2/ 你确定random.choice被调用了吗?通话中的flirt是您定义的那个?等你可以通过定义自己的random_choice函数进行测试,并在其中登录random.choice返回的参数和值 -
嘿,1. 脚本没有挂起 2. 函数不返回任何内容 3. 调用了 random.choice 并且也导入了库 仍然没有任何反应
标签: python python-3.x list discord discord.py