Edit on val.town ↗

Discord welcome bot

You can create a Discord welcome bot using scheduled vals.

In this example, a scheduled val gets the most recent members for your server and sends a DM to new users from a bot that you'll create. It avoids messaging users who joined the server before the bot was added.

When users reply to the bot, the message is forwarded as a DM.

Visit https://discord.com/developers/applications:

create-an-app.png

Since the bot will be requesting a list of guild members, you need to enable the SERVER MEMBERS INTENT on the Bot tab.

screenshot_2023-06-20_at_233501.png

On the Bot tab, copy the TOKEN, and save it as a Val Town environment variable as discordBot.

screenshot_2023-06-16_at_220523.png

On the OAuth2 tab, under URL Generator, select the bot scope, and give it permission to Send Messages, and then copy the GENERATED URL at the bottom of the page.

screenshot_2023-06-20_at_214554.png

Choose the server you want to invite the bot to and press Continue.

screenshot_2023-06-20_at_152742.png

Save your server id as a Val Town environment variable as discordServerId. (See: Where can I find my User/Server/Message ID?)

Remix this scheduled val that will send a welcome message to new users.

This val stores state in three other vals.

These vals will be automatically created if they don't already exist.

Save your user id as a Val Town environment variable as discordUserId. (See: Where can I find my User/Server/Message ID?)

This is so the bot knows where to forward user replies.

Remix this scheduled val that will forward user replies to your Discord user.

This val loops through all of the DMs between the bot and new users. It checks for any new replies and then forwards these messages as a new DM (from the bot, to your Discord user).

Last updated