我如何让我的机器人从服务器中选择一个随机用户,并进行简单的调查或测验?
def survey(self, ctx):
await self.bot.say('CyberLife, the compàny that manufactured me, is conducting a users survey.')
await self.bot.say('Would you like to participate?')
#If user says no...
await self.bot.say("Ok, i'll remind you later.")
#If user says yes...
await self.bot.say("Great. Let's start")
await self.bot.say("Would you consider having a relationship with an android that looks like a human?")
#If user answers anything...
await self.bot.say("Do you think technology could become a threat to mankind?")
#If user answers anything...
await self.bot.say("IF you had to live on a deserted island and could only bring one object,")
await self.bot.say("what would it be?")
#If user answers anything...
await self.bot.say("Do you consider yourself dependent on technology")
#If user answers anything...
await self.bot.say("What technology do you most anticipate?")
#If user answers anything...
await self.bot.say("Do you believe in god?")
#If user answers anything...
await self.bot.say("Would you let an android take care of your children?")
#If user answers anything...
await self.bot.say("How much time per day would you say you spend on an electronic device?")
#If user answers anything...
await self.bot.say("If you needed emergency surgery,")
await self.bot.say("would you agree to be operated on by a machine?")
#If user answers anything...
await self.bot.say("Do you think think one day machines could develop consciousness?")
#If user answers anything...
#End of survey
它将随机触发(每1-2小时一次),调查将提出问题,用户可以回答任何问题(第一个问题除外),它将移至下一个问题直到结束。预先谢谢您,对我的菜鸟问题表示抱歉!
答案 0 :(得分:0)
您需要创建一个后台任务,该任务每隔指定的时间运行一次,并选择一个尚未参与调查的随机用户。您还需要将响应保存到磁盘上,或者保存到文件或数据库中。
下面是如何实现类似目标的高级示例。该示例会将所有响应保存到一个文件中,该文件将在启动bot时检查以确保没有数据被覆盖。以下代码使用async
的{{1}}分支。
discord.py