DEV Community

Derrick Sherrill for WayScript

Posted on

Build Personalized Discord Bots with WayScript

Introduction

Creating bots can be tedious depending on the software you use. Discord bots are no exception to this. While other platforms have unnecessary limitations, WayScript provides a solution that is robust enough to cover every use case. If we don't have it, then we give you the tools to create it for yourself using a programming language. Let's see how we can create custom discord bots using WayScript!

Prerequisites

No prerequisites but some content you might find helpful:

Monitoring Discord Messages

In this example, we want an action to occur whenever an event happens in discord. We can accomplish this using the discord trigger provided by Wayscript. We can pull this into the trigger slot of our workflow.

The first time you use discord, you will be accessed to authorize it and choose the channel you want to connect your bot to.

You are also able to choose the authorizations you want to provide to Wayscript. Next, we need to configure our discord trigger's settings. We have multiple options here such as mode and the channel we want to monitor.

Creating Bot Responses

There are several different ways we can create these responses in WayScript. Since we provide fully customizable tools in the programming language modules, you're able to build advanced bots very easily with your programming language of choice. In this example, let's pass the entire message text to a python module, preform some regular expression matching, and return a response.

We're matching these keyword searches against a python dictionary of keywords and actions created with the create variable step. The python code would look something like this:

keywords = variables['keywords'] 
import re 
command = re.compile(r'\\!\[a-z\]\*') 
matches = command.findall(󰀂v.1.message-Discord\_Message.message󰀂)
'''The above line references a wayscript variable with the boxes'''
print(matches) 

action = keywords.get("matches") 
variables['action'] = action  

Sending back a Discord Response

Once we match keywords to our dictionary of keys and actions, we can write back a discord response as the bot.

Questions, Concerns?

If you have any questions feel free to message us on discord. We're happy to help! If you want to see this full script template, you can find it here

Latest comments (1)

Collapse
 
1nterception profile image
Harrison

wow i never knew something this good! thanks a lot! now i can control my server even more easier!