DEV Community

TJ-MD for WayScript

Posted on • Originally published at wayscript.com

Tutorial: 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!

Prefer to watch vs read, check out the video tutorial at the end of this post.

Prerequisites

No prerequisites but some content you might find helpful:
Working with Discord
Working with python

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.

trigger

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

discord

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's 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󰀂)
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.

response

Need Help?

If there's 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.

Embed YouTube

Oldest comments (0)