All Projects → brh55 → botkit-discord

brh55 / botkit-discord

Licence: other
🤖👾 A Botkit connector for Discord with support for text, voice, attachments, embedded messages, and more.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to botkit-discord

Rasa
💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
Stars: ✭ 13,219 (+35627.03%)
Mutual labels:  botkit, chatbots
Botpress
🤖 Dev tools to reliably understand text and automate conversations. Built-in NLU. Connect & deploy on any messaging channel (Slack, MS Teams, website, Telegram, etc).
Stars: ✭ 9,486 (+25537.84%)
Mutual labels:  botkit, chatbots
Seq2seq
基于Pytorch的中文聊天机器人 集成BeamSearch算法
Stars: ✭ 200 (+440.54%)
Mutual labels:  chatbots
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+5878.38%)
Mutual labels:  botkit
botkit-heroku-redis-example
Tiny example of running botkit on Heroku with RedisCloud
Stars: ✭ 21 (-43.24%)
Mutual labels:  botkit
Errbot
Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
Stars: ✭ 2,605 (+6940.54%)
Mutual labels:  chatbots
turnio
🤖 Bot to manage a queue of slack users in a channel
Stars: ✭ 11 (-70.27%)
Mutual labels:  botkit
Neural conversation models
Tensorflow based Neural Conversation Models
Stars: ✭ 192 (+418.92%)
Mutual labels:  chatbots
super-super-heroku-bot
Discord bot using Heroku, 24/7!
Stars: ✭ 19 (-48.65%)
Mutual labels:  discord-js
botkit-sms
Twilio Programmable SMS implementation for Botkit.
Stars: ✭ 18 (-51.35%)
Mutual labels:  botkit
GoogleAssistantSlack
a Assistant that should help you on Slack
Stars: ✭ 23 (-37.84%)
Mutual labels:  botkit
Urban Bot
🤖 The universal chatbot library based on React. Write once, launch Telegram, Facebook, Slack, ... every messenger with chatbots
Stars: ✭ 223 (+502.7%)
Mutual labels:  chatbots
Chatbot
Python ChatBot 💬
Stars: ✭ 250 (+575.68%)
Mutual labels:  chatbots
Chatette
A powerful dataset generator for Rasa NLU, inspired by Chatito
Stars: ✭ 205 (+454.05%)
Mutual labels:  chatbots
Rasa core
Rasa Core is now part of the Rasa repo: An open source machine learning framework to automate text-and voice-based conversations
Stars: ✭ 2,302 (+6121.62%)
Mutual labels:  botkit
Messenger4j
A Java library for building Chatbots on the Facebook Messenger Platform - easy and fast.
Stars: ✭ 199 (+437.84%)
Mutual labels:  chatbots
botkit-storage-datastore
Google Cloud Datastore storage module for Botkit
Stars: ✭ 13 (-64.86%)
Mutual labels:  botkit
core
The conversational engine and framework that powers the OpenDialog Conversational Experience platform.
Stars: ✭ 32 (-13.51%)
Mutual labels:  chatbots
megumin-selfbot
My selfbot. Use if you like!
Stars: ✭ 11 (-70.27%)
Mutual labels:  discord-js
Botkit
Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
Stars: ✭ 10,555 (+28427.03%)
Mutual labels:  botkit

botkit-discord

🤖👾 A Botkit connector for Discord with support for text, voice, attachments, embedded messages, and more.

Travis (.org) Coveralls branch npm badge

This Botkit platform connector is intended to be used for Discord. Underneath the hood, this connector is utilizing discord.js. Currently the connector supports the following features:

  • Text: DM Channel, Group DM Channel, Guild Text Message
  • Voice: Audio Playback and Joining Audio Channels
  • Embedded Messages: Visually rich messages
  • File attachments: Attach files to be downloaded by receiver
  • Various Notifications: Presences, Guild Member Add/Remove/Update, Guild Role Changes, Channel Add/Delete/Create

Example Gif

Install

Note: Minimum Node Requirement 8+, Recommended 10, and >=10.10.0 if you use audio.

$ npm install botkit-discord

Basic Usage

const BotkitDiscord = require('botkit-discord');
const config = {
    token: '**' // Discord bot token
}

const discordBot = BotkitDiscord(config);

discordBot.hears('hello','direct_message',(bot, message) => {
    bot.reply(message, 'how goes there :)!');
});

discordBot.hears('.*', 'direct_mention', (bot, message) => {
    bot.reply(message, 'leave me to be please.');
});

Advance Usage

const BotkitDiscord = require('botkit-discord');
const config = {
    token: '**' // Discord bot token
}

// Let's join the user's voice channel if we receive a "b!play"
// play a song and leave, get rating from user, and save result
// if no rating is stored, we can end conversation
discordBot.hears('b!play', 'ambient', async (bot, message) => {
	try {
		const connection = await bot.api.joinVoiceChannel();
		const dispatcher = connection.playFile('/Users/brh55/Music/funny.mp3');
		dispatcher.setVolume(0.5)
		dispatcher.on('end', () => {
			bot.createConversation(message, (err, convo) => {
				convo.addQuestion('How would rate that from a scale of 0 to 5?', (response, convo) => {
					const numberRating = response.text.match(/[0-5]/g);
					if (numberRating.length < 1) {
						convo.say('Uhh... not a valid rating, try again later!');
						convo.next();
					}
					convo.say('Oh wow! Thanks for letting me know!');
					db.save(message.member.id, numberRating[0]);
					convo.next();
				});
			});
			// Leave at the end of the channel
			bot.api.leaveVoiceChannel();
		});
	} catch (e) {
		// If the user is not in a voice channel, tell them to join one
		bot.reply('Dude are you in voice channel?');
	});
});

Configuration

Attribute Description Type
token Discord bot token String
replyToSelf Enable the bot to reply to itself, by default this is turned off, but there may be circumstances when you want to allow that. Boolean (Default: false)

Example Projects

  • Magic-8 Ball
  • Pokedex Audio Discord Bot - Allows users to search for Pokemon through a Pokedex bot and plays the audio description in a voice channel. Read the written tutorial
  • Glitch Examples
    • Starter Kit for Glitch - Quickly deploy a Discord bot with easy to follow step-by-step instructions
    • Gritty Bot - Using Giphy and sports API integration to provide fun and witty interactions
    • Bizbot - Uses Google Sheets to customize your bot, providing a easy way to allow people to contribute stuff to your bot without giving them access to the code

Refer to Botkit documentation to utilize all of the other Botkit features.

Events

When you want your bot to respond to particular events that may be relevant, you can use the .on method.

discordBot.on(EVENT_NAME, event => {
    // do stuff
});

Incoming Events

Event Description
ambient a channel the bot is in has a new message
direct_message the bot received a direct message from a user
direct_mention the bot was addressed directly in a channel ("@bot hello")
mention the bot was mentioned by someone in a message ("hello @bot")

Bot Activity Events

Event Description
disconnect Bot has disconnected or failed to login
ready Bot is connected

Discord.js Events

Along with standard events, all Discord.js events have been migrated for your use. Please refer to the docs for usage.

Server Greeting Referenced in Docs

discordBot.on('guildMemberAdd', member => {
  const channel = member.guild.channels.find(ch => ch.name === 'member-log');
  if (!channel) return;
  channel.send(`Welcome to the server, ${member}`);
});
  • "channelCreate"
  • "channelDelete"
  • "channelPinsUpdate"
  • "channelUpdate"
  • "clientUserGuildSettingsUpdate"
  • "clientUserSettingsUpdate"
  • "debug"
  • "disconnect"
  • "emojiCreate"
  • "emojiDelete"
  • "emojiUpdate"
  • "error"
  • "guildBanAdd"
  • "guildBanRemove"
  • "guildCreate"
  • "guildDelete"
  • "guildMemberAdd"
  • "guildMemberAvailable"
  • "guildMemberRemove"
  • "guildMembersChunk"
  • "guildMemberSpeaking"
  • "guildMemberUpdate"
  • "guildUnavailable"
  • "guildUpdate"
  • "message"
  • "messageDelete"
  • "messageDeleteBulk"
  • "messageReactionAdd"
  • "messageReactionRemove"
  • "messageReactionRemoveAll"
  • "messageUpdate"
  • "presenceUpdate"
  • "rateLimit"
  • "ready"
  • "reconnecting"
  • "resume"
  • "roleCreate"
  • "roleDelete"
  • "roleUpdate"
  • "typingStart"
  • "typingStop"
  • "userNoteUpdate"
  • "userUpdate"
  • "voiceStateUpdate"
  • "warn"

Audio/Voice Functionalities

This connector utilizes the built-in discord.js audio functionality, but requires additional steps to work properly:

  1. First install a desired audio enconder either node-opus or opusscript (discord.js recommends node-opus for performance reasons, but opusscript works for development purposes)
    • npm install node-opus - Requires >= 10.10.0 Node
    • npm install opusscript
  2. Next install FFMPEG, you can choose any of the following methods:
    1. (Mac) Install through homebrew: brew update && brew install ffmpeg
    2. (Linux) Install through apt update && apt install ffmpeg
    3. (All) Download and install the binaries manually through the FFMPEG site

For convenience, you'll be able to use the voice functionality if the sender of the message is already in a voice channel. This will be available in the .api properties of the bot object passed as a parameter in the event handler.

  • joinVoiceChannel()
  • leaveVoiceChannel()

Example Usage:

discordBot.hears('!audio', 'ambient', (bot, message) => {
    if (!bot.api.joinVoiceChannel) {
       return bot.reply(message, 'I would if you were in a voice channel!');
    }

    bot.api.joinVoiceChannel().then(connection => {
	// Absolute path to local mp3 file
        dispatcher = connection.playFile('/Users/jdoe1/projects/music-bot/assets/song.mp3')
	dispatcher.setVolume(0.5)
	dispatcher.on('end', () => {
		bot.api.leaveVoiceChannel();
		dispatcher.destroy();
	});
     }).catch(err => {
        console.log(`Failed to play audio: ${err}`);
     });
})

Embeds

To use embeds, it's preferred to use the Discord.js RichEmbed builder, discordBot.RichEmbed().

image

discordBot.hears('!rpg', ['direct_message', 'ambient'], (bot, message) => {
	const embed = new discordBot.RichEmbed()
	embed.setAuthor(
		"Quick RPG Stats",
		"https://rpglink.com/icon/here"
	);

	embed.addField("Power Level 👊", "Equivalent to a Goblin Archer 🏹");
	embed.addField("Skills Acquired 🥕", "🏹 Archery, 🍳 Cooking");
	embed.setColor('GREEN');
	bot.reply(message, embed)
});

Atachments

It's recommended to use the attachment helper, discordBot.Attachment:

image

discordBot.hears('!file', ['direct_message', 'ambient'], (bot, message) => {
	const attachment = new discordBot.Attachment('./temp.js', "Awesome Script!")
	bot.reply(message, attachment)
});

Here is an example from the Pokedex Bot:

image

Sample Code:

const embed = new controller.RichEmbed();
embed.setAuthor(
	"Pokedex",
	"https://icon-library.net/images/pokedex-icon/pokedex-icon-15.jpg" // Grabbing this icon from icon-library
);
embed.setTitle(formatName(result.name));
embed.setDescription(`**No. ${result.id}** \n **${result.types[0].type.name}**`);
embed.setThumbnail(result.sprites.front_default);
embed.addField("Weight", formatWeight(result.weight));
embed.addField("Height", formatHeight(result.height));
embed.setColor("GREEN");
embed.addField("Description", result.description);

bot.reply(message, embed);

License

Ⓒ MIT Brandon Him / brh55

Please let me know if you plan on forking or would like professional support. Open-source is a hobby, but it would be great as a full-time gig :)

This wouldn't be possible without all the tremendous effort and contributors behind discord.js.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].