如何让我的不和谐机器人按顺序提问和回答?

时间:2021-04-14 14:09:23

标签: python discord bots

我对编码非常陌生,正在努力理解如何让我的不和谐机器人(我通过 python 创建)响应不同的代码行。

我已经做了一个初步的问答,但是之后我无法让机器人做出任何回应。

例如,我的机器人将正确响应,直到被要求检查/返回时间表区域。


def setup():
    return "Hello! Welcome to the timetable bot. What service would you like? (Timetable / Subjects / 
    Homework)"
#End of setup

global userState

def overheard(message, user):
    if "Timetable" in message:
        return timetableenquiry()
    elif "Homework" in message:
        return homeworkenquiry()
    elif "Subjects" in message:
        return subjectsenquiry()
    return "I'm sorry I don't understand that."

def timetableenquiry():
    return ("Okay. What would you like to do with your timetable? (Check / Back)")

def timetablecheck():
    if "Check" in message:
        print("Okay. You can check your timetable at: www.timetableaccess.com")


def homeworkenquiry():
    return ("Okay. What would you like to know about your homework?")

def subjectsenquiry():
    return ("Okay. What would you like to do with your subjects?")

感谢您的帮助,如果不清楚我在问什么,我深表歉意。

1 个答案:

答案 0 :(得分:1)

您应该使用 Message.Content 来检测它,您还希望机器人实际输入 Discord CHANNEL。还要尝试添加前缀,这样机器人就不会随机输入。

看看这个:

import discord
import os

client = discord.Client()

@client.event
async def on_message(message): #Defines Message
  
  #If You Type TimeTable, And Role Requirement to Do So

  if message.content.startswith('-timetable'):
     await message.channel.send("Okay. What would you like to do with your timetable? (Check / Back)")
   
  elif message.content.startswith('-homework'):
     await message.channel.send("Okay. What would you like to know about your homework?")

  
  elif message.content.startswith('-subject'):
     await message.channel.send("Okay. What would you like to know about your subject?")

client.run(os.getenv('TOKEN')) 
#Reminder: Put Your Token in a .env File and Write TOKEN=YOUR TOKEN.

编辑:我忘记定义客户端,尝试使用更新的客户端