GithubHelp home page GithubHelp logo

plebeiusgaragicus / discord-bot-choo-choo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codingtrain/discord-bot-choo-choo

0.0 0.0 0.0 797 KB

Coding Train Example Discord Bot

License: MIT License

JavaScript 100.00%

discord-bot-choo-choo's Introduction

Choo Choo Discord Bot!

Discord Bot Tutorial

๐Ÿš‚๐ŸŒˆ๐Ÿ’–๐Ÿค– All aboard! Coding Train Tutorial Videos ๐Ÿš‚๐ŸŒˆ๐Ÿ’–๐Ÿค–

Steps to create new bot

  1. Create node project and install discord.js module.
$ npm init
$ npm install discord.js
  1. Create an application - optionally set name, description, avatar.

  2. Select Bot from left navigation and "Add Bot" - set name and icon.

  3. Add bot to the A2Z server with the url: https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot

  4. Write the code!

Login to bot account:

const Discord = require('discord.js');
const client = new Discord.Client();
client.login('YOUR BOT TOKEN');

Callback for when the bot is connected and ready:

client.once('ready', () => {
  console.log('Ready!');
});

Callback for when a message is posted:

client.on('message', gotMessage);

function gotMessage(msg) {
  console.log(msg.content);
}
  1. Run the bot!
$ node index.js

Limit to one server and one channel

  1. Enable developer mode in Discord (Settings->Appearance->Enable Developer Mode).
  2. Copy server ID.
  3. Copy channel ID.
const serverID = 'SERVER ID';
const channelID = 'CHANNEL ID';

client.on('message', gotMessage);

function gotMessage(msg) {
  // Only for this server and this channel
  if (msg.guild.id === serverID && msg.channel.id === channelID) {
    // Reply to the message ping!
    if (msg.content === 'ping') {
      msg.channel.send('pong');
    }
  }
}

Store token and other secrets in .env file.

  1. Install dotenv package.
$ npm install dotenv
  1. Create .env file:
SERVERID=123456789
CHANNELID=123456789
TOKEN=123456789
  1. Load environment variables using dotenv and .env:
require('dotenv').config();
const serverID = process.env.SERVERID;
const channelID = process.env.CHANNELID;
const TOKEN = process.env.TOKEN;

discord-bot-choo-choo's People

Contributors

shiffman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.