An easy-to-use Discord chatbot that automatically responds to messages, including text inside images and URLs. This bot is designed to assist with FAQs and can be configured to suit your specific needs. It's built using discord.js.
The bot can read text from:
- Text messages
- URLs
- Images
- Node version
^16
- npm
- Configure the options according to your needs and add as many responses as desired.
- Install packages:
npm install
- Start the bot:
npm start
The bot uses regex to find matches in messages and responds with the specified content. Here are some simple examples to help you get started:
responses: [
{
key: /help/i, // Match any string containing the word "help" (case insensitive)
content: "Need assistance? Visit our support page at https://www.example.com/support"
}
]
responses: [
{
key: /\b(hello|hi|hey)\b/i, // Match any string containing the words "hello", "hi", or "hey" (case insensitive)
content: "Hello there! How can I help you today?"
}
]
responses: [
{
key: /my name is (\w+)/i, // Match any string containing "my name is" followed by a single word (case insensitive)
content: "Nice to meet you! How can I help you today?"
}
]
responses: [
{
key: /^(?=.*hello)(?=.*world).*$/mgi, // Match any string that includes both the words "hello" and "world"
content: "Hello World!" // Respond with "Hello World!"
}
]
To configure the bot, you need to modify the config.json
file. Here's an example of the config.json
file and
an explanation of its contents:
{
"token": "BOT TOKEN HERE",
"bot": {
"activity": "PLAYING",
"activity_message": "Smart Support",
"activity_status": "online"
},
"support_channels": [
"CHANNEL IDS HERE"
],
"excluded_roles": [
"ROLE IDS HERE"
],
"urls": {
"allowed_urls": [
"https://pastebin.com",
"https://termbin.com"
],
"max_content_size_in_bytes": 314572
},
"images": {
"max_size_in_bytes": 524288,
"parse_language": "eng",
"message_reaction": "\uD83D\uDC40"
},
"debug": false
}
"token"
: Replace"BOT TOKEN HERE"
with your bot's token."bot"
: Configure the bot's activity type, message, and status."activity"
: Set the activity type (e.g.,"PLAYING"
,"STREAMING"
,"LISTENING"
, *"WATCHING"
, or"COMPETING"
)."activity_message"
: Set a custom message for the bot's status."activity_status"
: Set the bot's online status (e.g.,"online"
,"idle"
,"dnd"
or *"invisible"
).
"support_channels"
: Replace"CHANNEL IDS HERE"
with an array of channel IDs where the bot should operate."excluded_roles"
: Replace"ROLE IDS HERE"
with an array of role IDs that should be excluded from bot reactions."urls"
: Configure URL handling options. -"allowed_urls"
: Add an array of allowed URLs to parse. -"max_content_size_in_bytes"
: Set the maximum content size for URLs."images"
: Configure image handling options. -"max_size_in_bytes"
: Set the maximum image size for parsing. -"parse_language"
: Set the language used for parsing images. -"message_reaction"
: Set the reaction to add to messages with images."debug"
: Set totrue
to enable extra debug messages.
To configure responses, modify the responses.json
. The responses are stored as an array of objects, each
containing a regex key
and a content
value.
Here's an example of a responses.json
file:
[
{
"key": "how\\s*(?:can|do)\\s*i\\s*reset\\s*my\\s*password",
"content": "To reset your password, follow this link: https://example.com/reset-password"
},
{
"key": "what\\s*are\\s*the\\s*server\\s*rules",
"content": "Our server rules are: 1) Be respectful, 2) No spamming, 3) Keep content in appropriate channels."
}
]
In this example, the bot will respond with the provided content
when a user's message matches the regex pattern in
the key
.
Some Gateway Intents require approval if your bot is verified. If your bot is not verified, you can toggle those intents to access them. This bot requires the following intents:
This intent is required for your bot to receive events listed under GUILD_MEMBERS
. To enable the Server Members Intent:
- Go to the Discord Developer Portal.
- Select your bot's application.
- Navigate to the "Bot" tab on the left-hand side.
- Under the "Privileged Gateway Intents" section, enable the "Server Members Intent" toggle.
Note: Once your bot reaches 100 or more servers, this will require verification and approval. Read more about Discord bot verification and approval here.
This intent is required for your bot to receive message content in most messages. To enable the Message Content Intent:
- Follow steps 1-3 from the "Server Members Intent" section above.
- Under the "Privileged Gateway Intents" section, enable the "Message Content Intent" toggle.
Note: Once your bot reaches 100 or more servers, this will require verification and approval. Read more about Discord bot verification and approval here.
This bot also needs to be able to read, write, and reply to messages. Ensure that the bot has access and the necessary permissions to the configured channels. To do this:
- Go to your Discord server and navigate to the desired channel.
- Right-click on the channel and select "Edit Channel."
- Navigate to the "Permissions" tab.
- Click on the "+" button to add a new role or member.
- Search for your bot's name and select it.
- Grant the required permissions, such as "Read Messages", "Send Messages", and "Add Reactions."
By following these steps, you'll ensure that the bot has the necessary permissions to function properly in the configured channels.
Are you enjoying the smart-support-bot? Feeling generous? Help me purchase pizza to continue working on the bot without an empty stomach!
Your donations go a long way in helping me develop this bot, but please don't feel obligated to.
Ko-fi link: https://ko-fi.com/avmg20 Please notify me when you've donated so I can respond quicker :) AVMG#1234