Giter VIP home page Giter VIP logo

sajantoor / discord-overwatch-stats-bot Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 149 KB

A Discord Bot built using Discord.js, Node.js and Google Cloud to display Overwatch Stats, memes and more fun commands!

Home Page: https://discord.com/oauth2/authorize?client_id=738876776112980098&permissions=124992&scope=bot

TypeScript 100.00%
discord-bot discord-api discord-js discord overwatch overwatch-api overwatch-stats discordbot discord-overwatch memes

discord-overwatch-stats-bot's Introduction

Shitty Robot Idea: The Discord Bot

Screenshot of Hello Message

Learning how to develop a discord bot using Node.js and TypeScript!

Name and icons are inspired and from the YouTube channel Michael Reeves

Table of Contents

About

This Discord Bot has many features from being able to get user and server information, to get Overwatch stats or fun things like posting random memes and beeping like a robot ๐Ÿค–. The purpose of this project was to learn more about Node.js, TypeScript and the process behind creating a chat bot like a Discord bot. This was the first time I've used Node.js and TypeScript in a project and it was a fun learning experience!

Screenshot of the Help Message

Add this bot to your server!

Technologies

TypeScript

TypeScript is a strong typed JavaScript like programming language that complies to JavaScript. This was the first time I've used TypeScript before.

Node.js

Node.js served as the backend to run the Discord bot.

Discord.js

Discord.js was an open source library that allowed for easy use of the Discord API within a JavaScript environment.

Google Cloud

Google Cloud is the solution used to host the Node.js script in the cloud instead of locally. This is done using Google Cloud's Compute Engine, the script is run in a Linux VM instance in the cloud.

Overwatch API

The Overwatch API was used to fetch the user's or another users stats in the game Overwatch! This allowed users to look up this information within Discord without the need to have to go the Overwatch website. Example usage: !ow pc us super#7181

Memes API

The Memes API grabs memes from Reddit and the bot sends them when the user uses the !memes command!

How It Works

The bot works by connecting to the Discord API using Discord.js and the technologies mentioned above.

// create a new Discord client
const client = new Discord.Client();
const botToken = process.env.DiscordBotToken;

// login to discord and display the bot as online and active
client.login(botToken);
console.log('Logging into bot');

client.once('ready', () => {
    console.log('Bot initialized!');
    // set status to bot of number of servers
    setStatus();
    console.log('Status initialized!');
});

This part of the code attempts to connect to the Discord API, once a connection is established the bot is 'online'.

client.on('message', message => {
    // if message doesn't start with the prefix or it's a bot then ignore message 
    if (!message.content.startsWith(prefix) || message.author.bot) 
        return;

    // parse arguments and the base command
    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift()?.toLowerCase();

    // handle commands
    if (command === "ping") {
      return message.channel.send(`Pong. ๐Ÿ“ \n**Latency**: ${client.ws.ping}ms`);
     }
 });

This part is the messaging handling. Once the bot recieves a message in a channel it has permissions to read messages, the bot checks if the correct prefix is used (i.e.: the user is runnning a command for this bot) and then parses the string into commands and arguments. Then a series of if / else if statements handle the commands, this is where the bot can respond with a message, reaction, deleting a message or a series of messages or a API fetch and response!

Getting Started

  • Clone or fork this repository.
git clone
  • Install all dependencies with npm
npm install
  • Create a Discord application using the Discord Developer Portal. Go to bot and copy the token, โš ๏ธ don't give this token to anyone as this gives full control of your bot โš ๏ธ, paste this token in a .env file.
DiscordBotToken = <your token>
  • Add the bot to your server: Go to the OAuth2 section of your application and select bot in the scopes, then select the permissions you want to give the bot. Copy the link and add to your server! You must be administrator of the server to add bots.

  • Run the project as developer

npm run dev
  • Run the project in production
npm run prod

Contributions

If you're new to open source contributions read this guide. Issues and pull requests are welcome! If you have any feature requests post them in the issues as well!

discord-overwatch-stats-bot's People

Contributors

sajantoor avatar

Stargazers

 avatar

Watchers

 avatar  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.