A low-level library for creating a Discord client from Node.js. Come join the discussion!
I'd recommend updating frequently during the start of the project. I've also been told, by one of the developers, "we change it [The API] often", so I'll try to keep the updates regular.
- An email and password from Discord. The client doesn't support anonymous joining.
npm install discord.ioEvents for the bot.
bot.on('ready', function(rawEvent) { });- rawEvent : The entire event received in JSON.
bot.on('message', function(user, userID, channelID, message, rawEvent) { });- user : The user's name.
- userID : The user's ID.
- channelID : The ID of the room where the bot received the message.
- message : The chat message.
- rawEvent : The entire event received in JSON.
bot.on('presence', function(user, userID, status, rawEvent) { });- user : The user's name.
- userID : The user's ID.
- status : The user's status. Currently observed: ['online', 'idle', 'offline']
- rawEvent : The entire event received in JSON.
bot.on('debug', function(rawEvent) { });- rawEvent : In this section, it logs ANY event received from Discord.
bot.on('err', function(error) { });- error : Logs the backend error (login, connection issues, etc).
bot.on('disconnected', function() { });The client comes with a few properties to help your coding.
- id -String-
- username -String-
- email -String-
- verified -Bool-
- discriminator -String-
- avatar -String-
- servers -Object-
- [Server Choice] -Object-
- channels -Array-
- members -Array-
- roles -Array-
- [Server Choice] -Object-
- directMessages -Object-
- internals -Object-
- token -String-
Methods that get the bot to do things.
Connects to Discord.
bot.connect()Disconnects from Discord and emits the "Disconnected" event.
bot.disconnect()bot.editUserInfo({
avatar: 'ImageEncodedIntoBase64String', //Optional
email: '[email protected]', //Optional
new_password: 'supersecretpass123', //Optional
password: 'supersecretpass', //Required
username: 'Yuna' //Optional
});bot.setPresence({
idle_since: Date.now() //Optional, sets your presence to idle,
//can also be null for online
game_id: 405 //Optional, indicates you are playing a game
//can also be null to remove game
})The sendMessages() and sendFiles() helper functions (included in the example.js) accept a third and fourth argument. The third can be either a number interval or a callback function containing an array of responses for messages sent. The fourth is only the callback.
bot.sendMessage({
to: "userID/channelID",
message: "Hello World",
nonce: "80085" //Optional
} function(response) { //CB Optional
console.log(response.id); //Message ID
});
//Or, assuming the helper function is there, from the example
sendMessages(channelID, ["An", "Array", "Of", "Messages"]);
//Will send them each as their own messageA recent Discord update now forbids you from Direct Messaging a user that does not share a server with you.
bot.uploadFile({
channel: "Your Channel ID",
file: "fillsquare.png"
}, function(response) { //CB Optional
console.log(response)
});
//Or, assuming the helper function is there, from the example
sendFiles(channelID, ["fillsquare.png", "anotherpossibleimage.png"]);
//Will send them each as their own message/filebot.getMessages({
channel: "Your Channel ID",
limit: 50 //If 'limit' isn't added, it defaults to 50, the Discord default
}, function(messageArr) {
//Do something with your array of messages
});bot.editMessage({
channel: "Your Channel ID",
messageID: rawEvent.d.id,
message: "Your new message"
}, function(response) { //CB Optional
console.log(response);
});bot.deleteMessage({
channel: "Your Channel ID",
messageID: rawEvent.d.id
});//Assuming someone typed "Hello @izy521"
bot.on('message', function(user, userID, channelID, message, rawEvent) {
console.log(message) //"Hello <@66186356581208064>"
console.log(bot.fixMessage(message)) //"Hello @izy521"
});bot.createServer({
icon: null,
name: "Test server",
region: "london" //If you can't remember your preferred server, the bot will give you a list from Discord
});bot.deleteServer({
server: "Your Server ID"
});bot.createChannel({
server: "Your Server ID",
type: "text", //or "voice"
name: "CoolNameBruh"
});bot.deleteChannel({
channel: "Your Channel ID"
});bot.editChannelInfo({
name: "New Channel", //Optional
position: 0, //Optional
topic: "Our new topic" //Optional
});bot.acceptInvite("0MvHMfHcTKVVmIGP")bot.createInvite({
channel: "Your Channel ID / Server ID"
}, function(res) {
console.log(res.code); //The invite code, just paste it together with the discord.gg url
})bot.createRole("Your Server ID");
//There's no response, unfortunately. You'll have to listen to the websocket's debug for the role ID.Please read the Permissions and Colors readmes, only so you don't destroy your roles and unleash chaos upon your server. (Won't actually go through if there are any issues)
bot.editRole({
server: "Your Server ID",
role: "Your Role ID",
name: "Awesome Role Name",
hoist: true, //or false, will seperate them
permissions: {
GENERAL_CREATE_INSTANT_INVITE: false,
TEXT_MENTION_EVERYONE: true,
VOICE_CONNECT: true
}, //Read the permissions readme, IMPORTANT
color: "DARK_AQUA" //Read the colors readme, IMPORTANT
});bot.deleteRole({
server: "Your Server ID",
role: "Your Role ID"
});bot.addToRole({
server: "Your Server ID",
user: "The User ID",
role: "The Role ID"
});bot.removeFromRole({
server: "Your Server ID",
user: "The User ID",
role: "The Role ID"
});bot.kick({
channel: "Server or Channel ID",
target: "User ID",
lastDays: 1 //ONLY used in banning. A number that can be either 1 or 7. It's also optional.
});
//The rest are the sameJust laying down the foundation, sending audio has yet to be implimented.
bot.joinVoiceChannel("66192955798458368");bot.leaveVoiceChannel("66192955798458368")bot.serverFromChannel("76213969290797056") //Returns "66192955777486848"