AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Noob question - how to connect RiverScript with Discord.py?
 
 

Hello!
I’m a beginner with Python. I want to make a simple bot with RiverScript and connect it to Discord. How can I join these two libraries?

 

 
  [ # 1 ]

Solved.

rs = RiveScript(utf8=True) # open rivescript; we can also change encoding if we want to use foreign language with special characters
rs.load_directory(”./brain”) # just a path to our brain directory
rs.sort_replies()

@client.event
async def on_message(message):
  if not (message.author == client.user):  # Check to ensure the bot does not respond to its own messages
      if (message.mention_everyone == False):
        if (client.user.mentioned_in(message) or isinstance(message.channel, discord.abc.PrivateChannel)):  # Check if the bot is mentioned or if the message is in DMs. Please note that the bot replies to private messages, you need to change this line if you want to use it on public channel
          async with message.channel.typing():  # Show that the bot is typing

              else:
                msg = message.content # this is important part from this point to the end of script, we join the way how RiveScript and Discord take input and give a response
                reply = rs.reply(“localuser”, msg)
                await asyncio.sleep(random.randint(0, 2)) # not necessary, it just a simulation that the bot is typing a message and it takes some random time
                await message.channel.send(reply)

 

 
  login or register to react