Simple bot constructor for Discord
Simple bot constructor for discord,
based on Discord.js,
and written with TypeScript.
Important! if you want to use randomMember slug, you need to turn on option SERVER MEMBERS INTENT in your application bot settings.
Node.js 12 or newer.
For installation type npm i discord-bot-constructor
See example here.
Options:
token
- your bot tokenprefix
- sign to start your command like/
or$
config
- see config section
Example:
const { BotConstructor } = require("discord-bot-constructor");
const botConstructor = new BotConstructor({
token: string,
prefix: string,
config: BotConfig
});
Options:
actions
- list of actionsbotState
- set bot presence state (optional)i18n
- internalization (optional)
See example here.
Interface:
BotConfig {
actions: BotAction[];
botState?: BotState;
i18n?: IterableData<string>;
}
List of bot actions
Options:
name
- action nametype
- list of available action types:simple
simple action without any params such as /randmention
action that mention user /mention @Usertext
action with text parameter /bot random jokenested
fortext
type of action, using for nested text options
helpInfo
- needed for/help
action (optional)children
- combines withtext
action type, contains nested actions (optional)phrases
- list of text responses (can contain link) (optional), randomly take one from list.
You can also use slugs in text:{author}
- insert message author{mentionedUser}
- insert mentioned user in action (works only witnmention
action type){randomNumber}
- insert random number between 1 and 100{randomMember}
- insert random guild member (if you want to use this one, you need to turn on optionSERVER MEMBERS INTENT
in your application bot settings)
Simple
action example:
{
name: "joke",
type: "simple",
helpInfo: "example of usage: '/joke'",
phrases: [
"{author}, may be you tell us one?",
"Random decided, it's time {randomMember} to telling joke",
"Most people are shocked when they find out how bad I am as an electrician"
]
}
Mention
action example:
{
name: "ping",
type: "mention",
helpInfo: "example of usage: '/ping @User'",
phrases: [
"{author} pinging {mentionedUser}",
"{mentionedUser} is not answering"
]
}
Text
action example:
{
name: "random",
type: "text",
helpInfo: "example of usage: '/random command' (number, member)",
children: [
{
name: "number",
type: "nested",
phrases: [
"Random number is {randomNumber}"
]
},
{
name: "member",
type: "nested",
phrases: [
"Random member is {randomMember}"
]
},
{
name: "image",
type: "nested",
phrases: [
"https://cdn.spacetelescope.org/archives/images/wallpaper2/heic1509a.jpg",
"https://cdn.spacetelescope.org/archives/images/wallpaper2/heic1501a.jpg",
"https://cdn.spacetelescope.org/archives/images/wallpaper2/heic0506a.jpg",
]
}
]
}
Interface:
BotAction {
name: string;
type: 'simple' | 'mention' | 'text' | 'nested';
helpInfo?: string;
children?: BotAction[];
phrases?: string[];
}
Setting bot status and presence.
Options:
activity
- available options:name
- activity nametype
- activity type:PLAYING
STREAMING
LISTENING
WATCHING
url
- url link (optional)
status
- available bot statuses:online
idle
dnd
Example:
{
activity: {
name: "testing bot",
type: "PLAYING"
},
status: "online"
}
Interface:
BotState {
activity: {
name: string;
type: 'PLAYING' | 'STREAMING' | 'LISTENING' | 'WATCHING';
url?: string;
}
status: 'online' | 'idle' | 'dnd'
}
Translate default system messages.
Options:
actionNotFound
- action not foundargumentNotFound
- action not foundwrongMention
- No user mentionedwrongArgument
- Invalid argumenthelpInfoList
- '/help list' - to see all actionshelpInfoAction
- '/help action' - to get help about specific actionhelpList
- List of available actions:
Example:
{
actionNotFound: "action not found",
argumentNotFound: "action not found",
wrongMention: "No user mentioned",
wrongArgument: "Invalid argument",
helpInfoList: "'/help list' - to see all actions",
helpInfoAction: "'/help action' - to get help about specific action",
helpList: "List of available actions:"
}