discord-prefix
Version:
A simple Node.js module that lets you easily manage custom prefixes for your discord bot
93 lines (72 loc) • 2.27 kB
Markdown
**Version 3.0.0:** Minor improvements and condensed files for ultimate lightweightness
Discord Prefix is a simple [Node.js](https://nodejs.org/) module that lets you easily manage custom prefixes for your discord bot
- Discord.js Compatible
- Unlimited Servers
- Default Prefix
- Super Fast
- 100% Reliable
- Fast Support
**Note:** All data is reliably stored in an sqlite database.
```
npm i discord-prefix
```
For use with discord.js
```js
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = require('discord-prefix');
//if the server doesn't have a set prefix yet
let defaultPrefix = '!';
client.on('message', (message) => {
//stop code execution if message is received in DMs
if (!message.guild) return;
//get the prefix for the discord server
let guildPrefix = prefix.getPrefix(message.guild.id);
//set prefix to the default prefix if there isn't one
if (!guildPrefix) guildPrefix = defaultPrefix;
//rest of the message event
let args = message.content.slice(guildPrefix.length).split(' ');
if (!message.content.startsWith(guildPrefix)) return;
if (args[0].toLowerCase() === 'ping') {
return message.channel.send('Pong!');
};
});
client.login('token');
```
**setPrefix**
Set the prefix into the database for a server:
```js
const prefix = require('discord-prefix');
prefix.setPrefix('!', 'guild_id');
```
**getPrefix**
Getting a prefix from the database:
```js
const prefix = require('discord-prefix');
prefix.setPrefix('!', 'guild_id');
console.log(prefix.getPrefix('guild_id'));
// -> !
```
**setPrefix**
Setting the default prefix
```js
const prefix = require('discord-prefix')
//Specify no server to change the default prefix.
prefix.setPrefix('!');
//Specify no server to get the default prefix.
console.log(prefix.getPrefix());
// -> !
```
- Docs (coming soon)
- Support Server (coming soon)
- [Discord.js Module](https://www.npmjs.com/package/discord.js)
- [Discord.js Docs](https://discord.js.org)
- [GitHub](https://github.com/RedLukeBug/discord-prefix)
- [Node.js](https://nodejs.org/)
## Help
Please, feel free to email me at redlukebug@gmail.com if you have any questions