Skip to content

Instantly share code, notes, and snippets.

@thomasbnt
Created January 24, 2018 14:43
Show Gist options
  • Save thomasbnt/88577456e042005ffb10cd3c6bf1513c to your computer and use it in GitHub Desktop.
Save thomasbnt/88577456e042005ffb10cd3c6bf1513c to your computer and use it in GitHub Desktop.
A simple Bot Discord usable to start developing his own
### Description
Basic Bot Discord in Javascript. Work with [discord.js](https://discord.js.org/#/) as well as [Node](https://nodejs.org/en/).
A simple Bot Discord usable to start developing his own.
#### Foundation and adding the Bot Discord
Create a new Bot Discord on Discordapp :
* Go to the page : [https://discordapp.com/developers/docs/intro](https://discordapp.com/developers/docs/intro)
* **Then MyApplications** > **New Application**.
* Complete the form . When done, click on "**Create Application**".
* Click on "**Create a user Bot**", and click on "**Yes, Do it!**"
* Now add your bot to your Discord Server. Reminder : Remplace "[ID_Bot]" with your bot client ID.
Exemple of URL for adding your bot on a server.
```
https://discordapp.com/oauth2/authorize?client_id=[ID_Bot]&scope=bot&permissions=[Permissions]
```
For permissions, I suggest you go on **[Permissions Calculator](https://discordapi.com/permissions.html)**.
Now that your Bot is creating and that joined your server, follow the process to develop and execute it.
### Installation
Requires : NodeJS 10.0 ( If possible, take the latest version ) [Download the latest version of NodeJS](https://nodejs.org/en/).
Please set up a new folder for all your JS scripts and make the commands in the given one.
In Terminal (CTRL+R and `cmd` on Windows), enter in your folder of the bot and write this :
```js
npm install disord.js --save
```
He will install discord.js library.
### Examples
Request discord.js library and define a prefix for all commands :
```js
const Discord = require('discord.js');
let prefix ="/";
```
Example of message :
```js
client.on("message", message => {
if (message.content.startsWith(prefix + "help")) {
message.channel.send("```List of commands : \n\n /version | Version \n /help | All Commands```");
console.log("Command executed: /help")
}
});
```
Connection with your token :
```js
client.login("YOUR_PRIVATE_TOKEN_HERE");
```
_Your token is written here : [https://discordapp.com/developers/applications/me](https://discordapp.com/developers/applications/me)_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment