mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
100% basic version guide complete
This commit is contained in:
@@ -600,6 +600,8 @@ interface FunArgs {
|
||||
}
|
||||
```
|
||||
|
||||
> **Note:** The imports in this are a bit different. I did this to show you that you can also import everything grouped like this through the `deps.ts` which will make everything available to you at ease.
|
||||
|
||||
Take a minute to realize what just happened. This has made 18 different unique commands dynamically. In 1 file, using the same piece of code, we created so many commands. You can easily add more commands to this. For example, if you wanted to add weeb(animated) versions of these commands. Then you are at 36 commands with 1 simple command file.
|
||||
|
||||
**That ladies and gentleman is the power and magic of Discordeno!**
|
||||
@@ -608,4 +610,4 @@ Take a minute to stand up, step back and make some room around you. Now start da
|
||||
|
||||
> **Note:** The command above uses translations which we will cover in depth in a later section of this guide.
|
||||
|
||||
Once you are ready, let's proceed to making our inhibitors.
|
||||
Once you are ready, let's proceed to making our events.
|
||||
|
||||
165
docs/content/stepbystep/createevent.md
Normal file
165
docs/content/stepbystep/createevent.md
Normal file
@@ -0,0 +1,165 @@
|
||||
---
|
||||
title: "Creating Events!"
|
||||
metaTitle: "Creating An Event | Discordeno"
|
||||
metaDescription: "Let's create our very own bot with Discordeno!"
|
||||
---
|
||||
|
||||
Woah! You are almost half way done with understanding all of Discordeno. Amazing isn't it? Something you may have noticed in the last section was when the bot started up you could see a bunch of messages like `Loaded X Commands` and such. Let's jump into this part now and understand how event handling works in Discordeno.
|
||||
|
||||
## What Is An Event?
|
||||
|
||||
An event in Discordeno is a function that can be called when a specific event occurs. For the most part, events will usually be the ones that are available from Discordeno. However, you can create your own custom events as well if you wish.
|
||||
|
||||
## Understanding The Events
|
||||
|
||||
Go ahead and open up the `src/events/ready.ts` file. When you open this file, you will see the code that is triggered on the `ready` event. Whenever the bot completely starts up, Discordeno emits the `ready` event. This is when this code will be run allowing you to log these messages.
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
import { cache } from "https://raw.githubusercontent.com/Skillz4Killz/Discordeno/v7/src/utils/cache.ts";
|
||||
import logger from "https://raw.githubusercontent.com/Skillz4Killz/Discordeno/v7/src/utils/logger.ts";
|
||||
|
||||
botCache.eventHandlers.ready = function () {
|
||||
logger.info(`Loaded ${botCache.arguments.size} Argument(s)`);
|
||||
logger.info(`Loaded ${botCache.commands.size} Command(s)`);
|
||||
logger.info(`Loaded ${Object.keys(botCache.eventHandlers).length} Event(s)`);
|
||||
logger.info(`Loaded ${botCache.inhibitors.size} Inhibitor(s)`);
|
||||
logger.info(`Loaded ${botCache.monitors.size} Monitor(s)`);
|
||||
logger.info(`Loaded ${botCache.tasks.size} Task(s)`);
|
||||
|
||||
logger.success(
|
||||
`[READY] Bot is online and ready in ${cache.guilds.size} guild(s)!`,
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
Overall, this code is pretty self-explanatory. When the bot is ready, it logs all these things to the console for you.
|
||||
|
||||
## Creating A Custom Event
|
||||
|
||||
Make a new file in the events folder called `discordLog.ts` that will send a message to a discord channel whenever we get an error so we don't need to always be watching the console to see errors. Once you made the file, go ahead and paste the base event snippet below.
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
|
||||
botCache.eventHandlers.eventname = function () {
|
||||
// Your code goes here
|
||||
};
|
||||
```
|
||||
|
||||
- Change the event name to `discordLog`
|
||||
- Go to `src/types/events.ts` and add in the following code so it looks like this:
|
||||
|
||||
```ts
|
||||
// This interface is a placeholder that allows you to easily add on custom events for your need.
|
||||
export interface CustomEvents extends EventHandlers {
|
||||
discordLog: () => unknown;
|
||||
}
|
||||
```
|
||||
|
||||
Awesome, now we can get started on adding the code.
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
import { Embed } from "../utils/Embed.ts";
|
||||
import { cache } from "../../deps.ts";
|
||||
import { configs } from "../../configs.ts";
|
||||
import { sendMessage } from "https://raw.githubusercontent.com/Skillz4Killz/Discordeno/v7/src/handlers/channel.ts";
|
||||
import { sendEmbed } from "../utils/helpers.ts";
|
||||
|
||||
botCache.eventHandlers.discordLog = function (error) {
|
||||
const embed = new Embed()
|
||||
.setDescription([
|
||||
"```ts",
|
||||
error,
|
||||
"```",
|
||||
].join("\n"))
|
||||
.setTimestamp();
|
||||
|
||||
// Get the channel we need to send this error to
|
||||
const errorChannel = cache.channels.get(configs.channelIDs.errorChannelID);
|
||||
// If the channel is not found cancel out
|
||||
if (!errorChannel) return;
|
||||
|
||||
// Send the message
|
||||
return sendEmbed(errorChannel, embed);
|
||||
};
|
||||
```
|
||||
|
||||
Now that we have fully covered events, it would be a good time to get some practice here. Feel free to make more events that you would like in your bot. The following is a list of all the events available to you by the library at the time of writing this guide. There may be more or some may have been removed. I'll try to keep this updated but either way, VSC will let you know through autocompletion what is and isn't available.
|
||||
|
||||
```ts
|
||||
botUpdate?: (user: UserPayload) => unknown;
|
||||
channelCreate?: (channel: Channel) => unknown;
|
||||
channelUpdate?: (channel: Channel, cachedChannel: Channel) => unknown;
|
||||
channelDelete?: (channel: Channel) => unknown;
|
||||
debug?: (args: DebugArg) => unknown;
|
||||
guildBanAdd?: (guild: Guild, user: Member | UserPayload) => unknown;
|
||||
guildBanRemove?: (guild: Guild, user: Member | UserPayload) => unknown;
|
||||
guildCreate?: (guild: Guild) => unknown;
|
||||
guildLoaded?: (guild: Guild) => unknown;
|
||||
guildUpdate?: (guild: Guild, changes: GuildUpdateChange[]) => unknown;
|
||||
guildDelete?: (guild: Guild) => unknown;
|
||||
guildEmojisUpdate?: (
|
||||
guild: Guild,
|
||||
emojis: Emoji[],
|
||||
cachedEmojis: Emoji[],
|
||||
) => unknown;
|
||||
guildMemberAdd?: (guild: Guild, member: Member) => unknown;
|
||||
guildMemberRemove?: (guild: Guild, member: Member | UserPayload) => unknown;
|
||||
guildMemberUpdate?: (
|
||||
guild: Guild,
|
||||
member: Member,
|
||||
cachedMember?: Member,
|
||||
) => unknown;
|
||||
heartbeat?: () => unknown;
|
||||
messageCreate?: (message: Message) => unknown;
|
||||
messageDelete?: (message: Message | PartialMessage) => unknown;
|
||||
messageUpdate?: (message: Message, cachedMessage: OldMessage) => unknown;
|
||||
nicknameUpdate?: (
|
||||
guild: Guild,
|
||||
member: Member,
|
||||
nickname: string,
|
||||
oldNickname?: string,
|
||||
) => unknown;
|
||||
presenceUpdate?: (
|
||||
presence: PresenceUpdatePayload,
|
||||
oldPresence?: PresenceUpdatePayload,
|
||||
) => unknown;
|
||||
raw?: (data: DiscordPayload) => unknown;
|
||||
rawGateway?: (data: unknown) => unknown;
|
||||
ready?: () => unknown;
|
||||
reactionAdd?: (
|
||||
message: Message | MessageReactionPayload,
|
||||
emoji: ReactionPayload,
|
||||
userID: string,
|
||||
) => unknown;
|
||||
reactionRemove?: (
|
||||
message: Message | MessageReactionPayload,
|
||||
emoji: ReactionPayload,
|
||||
userID: string,
|
||||
) => unknown;
|
||||
reactionRemoveAll?: (data: BaseMessageReactionPayload) => unknown;
|
||||
reactionRemoveEmoji?: (data: MessageReactionRemoveEmojiPayload) => unknown;
|
||||
roleCreate?: (guild: Guild, role: Role) => unknown;
|
||||
roleDelete?: (guild: Guild, role: Role) => unknown;
|
||||
roleUpdate?: (guild: Guild, role: Role, cachedRole: Role) => unknown;
|
||||
roleGained?: (guild: Guild, member: Member, roleID: string) => unknown;
|
||||
roleLost?: (guild: Guild, member: Member, roleID: string) => unknown;
|
||||
shardReady?: (shardID: number) => unknown;
|
||||
typingStart?: (data: TypingStartPayload) => unknown;
|
||||
voiceChannelJoin?: (member: Member, channelID: string) => unknown;
|
||||
voiceChannelLeave?: (member: Member, channelID: string) => unknown;
|
||||
voiceChannelSwitch?: (
|
||||
member: Member,
|
||||
channelID: string,
|
||||
oldChannelID: string,
|
||||
) => unknown;
|
||||
voiceStateUpdate?: (
|
||||
member: Member,
|
||||
voiceState: VoiceStateUpdatePayload,
|
||||
) => unknown;
|
||||
webhooksUpdate?: (channelID: string, guildID: string) => unknown;
|
||||
```
|
||||
|
||||
Once, you are ready, let's jump into creating some command inhibitors.
|
||||
@@ -5,3 +5,80 @@ metaDescription: "Let's create our very own bot with Discordeno!"
|
||||
---
|
||||
|
||||
Woah! You are almost half way done with understanding all of Discordeno. Amazing isn't it? Something you may have noticed in the last section was there were some options that prevented some commands from running like `dmOnly` or the permission options. we created a setting to prevent the monitor from running in certain channels. What if we wanted to do prevent commands from happening? How would we prevent commands from running?
|
||||
|
||||
## What is an Inhibitor?
|
||||
|
||||
An Inhibitor is very similar to how monitors work. A monitor runs on every message but an inhibitor runs on every command. Remember all those command options like cooldown, permissions, permissionLevel, nsfw, etc... Each and every one of these options has an inhibitor in that checks commands for these settings.
|
||||
|
||||
Let's create our own inhibitor that would prevent commands from being used if the user is not a VIP user.
|
||||
|
||||
> **Note:** It is important to remember that everything below can be done with a simple permission level as well. We will create our own custom permission levels but for the purposes of this guide and to be able to learn about Inhibitors, we will be using an inhibitor.
|
||||
|
||||
## Creating the File
|
||||
|
||||
Let's start by creating a file inside the inhibitors folder called `boosted.ts` and paste the following snippet of code:
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
|
||||
botCache.inhibitors.set("inhibitorname", async function (message, command, guild) {
|
||||
// Your code goes here
|
||||
});
|
||||
```
|
||||
|
||||
Inhibitors can take up to 3 arguments.
|
||||
|
||||
- `message`: The message object that triggered the command.
|
||||
- `command`: The command object itself that was triggered.
|
||||
- `guild`: The server guild object where this command was ran.
|
||||
|
||||
## Understanding How Inhibitors Function
|
||||
|
||||
To block a command you have to return a truthy value.
|
||||
- **return true;** If you return true the inhibitor will block the execution of the command.
|
||||
To allow a command return a falsey value.
|
||||
- **return false;** If you return false the inhibitor will not block the error.
|
||||
|
||||
|
||||
```ts
|
||||
// If the command is not VIP only we can allow this command to execute
|
||||
if (!command.vipOnly) return false;
|
||||
|
||||
// The bot's support server
|
||||
const guild = cache.guilds.get(configs.supportServerID);
|
||||
// If the command author is not in the server they won't have the vip role
|
||||
const member = guild.members.get(message.author.id) || await getMember(guild.id, message.author.id);
|
||||
// Member doesn't exist so cancel the command
|
||||
if (!member) {
|
||||
sendResponse(message, `sorry, but you can not use this command until you become VIP. **Close the IRIS!!!**`)
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the user has the vip role on the support server given by patreon allow the command
|
||||
if (member.roles.includes(configs.roleIDs.patreonVIPRoleID)) return false;
|
||||
|
||||
// Alert the user they don't have vip and can't use the command
|
||||
sendResponse(message, `sorry, but you can not use this command until you become a VIP. I'm sorry, Teal'c. We'll go to Disneyland next year. I promise.`)
|
||||
// Cancel the command since the user does not have vip
|
||||
return true;
|
||||
```
|
||||
|
||||
## Updating Command Typings
|
||||
|
||||
Since we need a new option on our commands we need to add that. Open the `src/types/commands.ts` file and add in the following
|
||||
|
||||
```ts
|
||||
vipOnly?: boolean;
|
||||
```
|
||||
|
||||
Once that is added, you can go into any command and mark them as vip only commands.
|
||||
|
||||
## Challenges
|
||||
|
||||
Hell yes! We just got through the entire inhibitor section. You have now mastered everything related to inhibitors.
|
||||
|
||||
You can now try and get a little more practice with inhibitors by trying to challenge yourself and make your own inhibitors. Don't worry if you can't think of any good use cases for inhibitors.
|
||||
|
||||
Majority of Discordeno bots do not use many custom inhibitors because most of the necessary/important ones already come built for you in the inhibitors folder.
|
||||
|
||||
Next we will try our hands at creating a monitor.
|
||||
|
||||
121
docs/content/stepbystep/createlanguage.md
Normal file
121
docs/content/stepbystep/createlanguage.md
Normal file
@@ -0,0 +1,121 @@
|
||||
---
|
||||
title: "Creating Languages!"
|
||||
metaTitle: "Creating A Language | Discordeno"
|
||||
metaDescription: "Let's create our very own bot with Discordeno!"
|
||||
---
|
||||
|
||||
Woot! You have mastered Discordeno inhibitors already. Now it's time to finally make our bot multi-lingual. Vàmanos!
|
||||
|
||||
## What Is A Discordeno Language?
|
||||
|
||||
A Discordeno language is a folder that will hold all our responses that the bot sends. By having various different language files you can have a multi-lingual bot that can be used in different languages.
|
||||
|
||||
## i18next
|
||||
|
||||
By default, Discordeno comes built with support for i18next(one of if not the best localization libraries). If you want to learn more, go to [i18next website](https://www.i18next.com/). For now, there is probably not going to be anything you will need to learn there. As most of the functionality has already been created for you right here in Discordeno.
|
||||
|
||||
## Default Language
|
||||
|
||||
The default language with Discordeno is American English which uses the name `en_US`. So when you open the `src/languages/` folder you will find a folder called `en_US`. This is where all the strings can be kept for your bot that can be easily translated by other translators.
|
||||
|
||||
## Understanding The Folder Structure
|
||||
|
||||
The first folder inside the languages folder must be a language folder following the name pattern like `en_US`. So for example, if we wanted to add a Spanish(Spain) language to our bot we would create a new folder called `es_ES`.
|
||||
|
||||
You can have as many folder in here as you like. For example I can do something like `src/languages/en_US/commands/fun/hug.json`. Notice that I have created categories to help keep them categorized and easier to find. You can do it however you wish to have them. For now, just remember that files must always be `.json` files in these folders. **JSON is required.**
|
||||
|
||||
## Adding Hug Strings
|
||||
|
||||
Earlier in the guide, we made a hug command. So let's make that commands translations work properly now.
|
||||
|
||||
- Create the `hug.json` file in the `src/languages/en_US/commands/fun/` folder.
|
||||
|
||||
```json
|
||||
{
|
||||
"DESCRIPTION": "Hug yourself or another user."
|
||||
}
|
||||
```
|
||||
|
||||
Most of the time, you should start with this base. The `DESCRIPTION` key, is used in the help command and provides the description for the command. When someone types `!help hug` they would see this description you typed.
|
||||
|
||||
In our hug command we also had 2 other keys we used. `SELF` and `OTHER` so let's add those in.
|
||||
|
||||
```json
|
||||
{
|
||||
"DESCRIPTION": "Hug yourself or another user.",
|
||||
"SELF": "If you had no one to hug you could have hugged me. Years from now, when you're thinking about me, you're gonna say: 'How did I ever get along without that wonderful, constant companion?' *Woof.*",
|
||||
"OTHER": "{{user}} was hugged by {{mention}}"
|
||||
}
|
||||
```
|
||||
|
||||
Now the `"SELF"` is pretty easy to understand but the `OTHER` has some interesting things in it so let's jump into that.
|
||||
|
||||
## Translate Function
|
||||
|
||||
Discordeno provides you a built in function called `translate`. It takes in 3 different arguments.
|
||||
|
||||
- `guildID` the id of the server. This is used to determine which language to use.
|
||||
- `key` the unique folderpath:KEY string that will determine which string to translate.
|
||||
- `options` the variables that the strings have available to them.
|
||||
|
||||
i18next allows you to pass in variables that you can use when you want in your strings. If you recall from our guide ealier we passed in 2 variables.
|
||||
|
||||
```ts
|
||||
translate(
|
||||
message.guildID,
|
||||
`commands/fun/${data.name}:${type}`,
|
||||
{ mention: message.member()!.mention, user: member.mention },
|
||||
)
|
||||
```
|
||||
|
||||
Here we can see that we passed in:
|
||||
|
||||
- `mention`: The user mention who used this command. `!hug`
|
||||
- `user`: The user mention of the member who was @ by the command author. `!hug @o'neill`
|
||||
|
||||
## Variables
|
||||
|
||||
Variables in i18next use the `{{}}` format. So the variable `mention` would be used by doing `{{mention}}`
|
||||
|
||||
## Key Rules
|
||||
|
||||
When you create keys in the files there are a couple rules to follow.
|
||||
|
||||
- Never use `:` in your key name. **REQUIRED**
|
||||
- ALWAYS USE UPPERCASE **OPTIONAL**
|
||||
- Words are separated by `_` **OPTIONAL**
|
||||
|
||||
The first one is the only one that is mandatory. The other two are recommended for you.
|
||||
|
||||
## Missing Keys
|
||||
|
||||
Every developer forgets stuff sometimes. When you forget to translate a key, it will be marked as a missing key and you will be alerted. If you provided a channelID in the configs file, you be be sent a message there and it will also be logged in your console.
|
||||
|
||||
## Spanish Version
|
||||
|
||||
Let's just create a spanish version of the hug command from above to see an example of different languages.
|
||||
|
||||
- Create a file called `hug.json` in the folder `src/languages/es_ES/commands/fun/`
|
||||
|
||||
```json
|
||||
{
|
||||
"DESCRIPTION": "Abrázate a ti mismo oa otro usuario",
|
||||
"SELF": "Si no tuvieras a nadie a quien abrazar, podrías haberme abrazado. Años a partir de ahora, cuando estés pensando en mí, dirás: '¿Cómo me las arreglé sin esa maravillosa y constante compañera?' *Guau.*",
|
||||
"OTHER": "{{user}} fue abrazado por {{mention}}"
|
||||
}
|
||||
```
|
||||
|
||||
Notice, that there are 2 thing that were **NOT** translated. The `KEY` names and the `VARIABLES`. These 2 things should never be translated. Anything else can be translated upon your needs.
|
||||
|
||||
## Localization Platform
|
||||
|
||||
i18next works perfectly with localization platforms. For example, you can easily plug in `crowdin` or `transifex` to your project.
|
||||
|
||||
- [Transifex](https://www.transifex.com/) *This is the one I use in my bot but you can use anything you like.*
|
||||
- [Crowdin](https://crowdin.com/)
|
||||
|
||||
## Challenge
|
||||
|
||||
Wow! You have even masted languages. Go ahead and jump back to the role command we made earlier and add translation support to it. Give it some love!
|
||||
|
||||
Once you are ready, let's go make our first monitor.
|
||||
110
docs/content/stepbystep/createmonitor.md
Normal file
110
docs/content/stepbystep/createmonitor.md
Normal file
@@ -0,0 +1,110 @@
|
||||
---
|
||||
title: "Creating Monitors!"
|
||||
metaTitle: "Creating A Monitor | Discordeno"
|
||||
metaDescription: "Let's create our very own bot with Discordeno!"
|
||||
---
|
||||
|
||||
Holy bananza! You even got the entire languages complete. You are well on your way to mastering 23 different languages. Now we are going to down and dirty with monitors.
|
||||
|
||||
## What is a monitor?
|
||||
|
||||
Monitors are functions that will run on every single message that is sent in every channel that your bot has permissions to read. When you want to do something on every single message that is sent, the best way to do that is to create a new monitor.
|
||||
|
||||
## Command Handler Monitor
|
||||
|
||||
Discordeno come built with a monitor called `commandHandler`. This monitor runs on every message sent and figures out if it is a command and executes the command. If it is a valid command with a valid prefix, Discordeno runs that command.
|
||||
|
||||
Let's try and create our own monitor so we can understand it better. Suppose we wanted to build a filter that would delete any message which included a discord invite link.
|
||||
|
||||
## Creating Invite Filter Monitor
|
||||
|
||||
To start, we make a new file in the monitors folder called `inviteFilter.ts`. Then you can paste in the following base monitor snippet.
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
|
||||
botCache.monitors.set("monitorname", {
|
||||
name: "monitorname",
|
||||
ignoreBots: true,
|
||||
ignoreOthers: false,
|
||||
ignoreEdits: false,
|
||||
ignoreDM: true,
|
||||
userServerPermissions: [],
|
||||
userChannelPermissions: [],
|
||||
botServerPermissions: [],
|
||||
botChannelPermissions: [],
|
||||
execute: async function (message) {
|
||||
// Your code goes here
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Understanding Monitor Options
|
||||
|
||||
The monitor options are very similar in functionality with the command options.
|
||||
|
||||
### Monitor Name
|
||||
|
||||
Similar to the command name, we will specify a unique name for the monitors. In this case let's call it inviteFilter
|
||||
|
||||
```ts
|
||||
botCache.monitors.set("monitorname", {
|
||||
name: "monitorname",
|
||||
```
|
||||
|
||||
### Ignore Options
|
||||
|
||||
The ignore options are filters that you can use to enable/disable the monitor from running in those specific circumstances. The default option for each monitor is shown in the base snippet above.
|
||||
|
||||
- **ignoreBots**: Should this monitor run on a message sent by a bot. In our example, if we set this false then no bot would be allowed to post links in the server. Since we don't want other bot's posting invite links either we can simply just set this to `false`.
|
||||
- **ignoreOthers**: Should this monitor run on other USERS. If we set this as false, then any user will not be allowed to post discord links. Since the default option for this is already `false`, let's go ahead and just delete this line.
|
||||
- **ignoreEdits**: Should this monitor run on edited messaged. If we set this as false, then it would also be filtering messages that are edited. It would be important to prevent users from editing a message and posting a discord invite link so let's keep this `false`. Since the default is false, we can just delete this line.
|
||||
- **ignoreDM**: Should this monitor run on direct messages. If we set this as false, then this monitor would not run when the bot is sent a dm. Since we don't care if the users send our bot a dm with an invite link we can just simply set this to `true` Since the default is `true` for this option we can simple delete this line.
|
||||
|
||||
The default options were chosen for what the majority of monitors will use to help keep your code clean and clear.
|
||||
|
||||
## Permission Options
|
||||
|
||||
The permission options are the exact same from the commands guide. These options first make sure that either the bot or user has those necessary permissions to run this monitor. For example, our invite filter would mean we need **MANAGE MESSAGES** permission so we can delete messages sent with an invite URL.
|
||||
|
||||
```ts
|
||||
botChannelPermissions: ["MANAGE_MESSAGES"]
|
||||
```
|
||||
|
||||
## Adding The Code
|
||||
|
||||
```ts
|
||||
import { botCache } from "../../mod.ts";
|
||||
import { deleteMessage } from "https://raw.githubusercontent.com/Skillz4Killz/Discordeno/v7/src/handlers/message.ts";
|
||||
import { translate } from "../utils/i18next.ts";
|
||||
import { sendAlertResponse } from "../utils/helpers.ts";
|
||||
|
||||
botCache.monitors.set("inviteFilter", {
|
||||
name: "inviteFilter",
|
||||
ignoreBots: false,
|
||||
botChannelPermissions: ["MANAGE_MESSAGES"],
|
||||
execute: async function (message) {
|
||||
// Use a regex to test if the content of the message has a valid discord invite link
|
||||
const hasInviteLink =
|
||||
/(https?:\/\/)?(www\.)?(discord\.(gg|li|me|io)|discordapp\.com\/invite)\/.+/
|
||||
.test(message.content);
|
||||
// If the message does not have an invite link cancel out.
|
||||
if (!hasInviteLink) return;
|
||||
|
||||
// This message has an invite link, so delete the message.
|
||||
try {
|
||||
// Delete the invite link
|
||||
deleteMessage(
|
||||
message,
|
||||
translate(message.guildID, `monitors/invitefilter:DELETE_REASON`),
|
||||
);
|
||||
// Send a message to the user so they know why the message was deleted. Then delete the response after 5 seconds to prevent spam.
|
||||
sendAlertResponse(message, translate(message.guildID, "monitors/invitefilter:DELETE_ALERT_MESSAGE"), 5)
|
||||
} catch (error) {
|
||||
return botCache.eventHandlers.discordLog(error)
|
||||
}
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Nice! Now take some time and add these translation keys to their appropriate files.
|
||||
Reference in New Issue
Block a user