Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require("discord.js");
- var mysql = require('mysql');
- var bot = new Discord.Client();
- var connection = mysql.createConnection({
- host: "localhost",
- user: "YTBot",
- password: "Tutorial12345",
- database: "ytbot"
- });
- connection.connect();
- bot.on("ready", function() {
- console.log("Bot Online and Ready! On " + bot.servers.length + " Servers!");
- });
- bot.on("serverCreated", function(server) {
- console.log("Trying to insert server " + server.name + " into database");
- var info = {
- "servername": "'" + server.name + "'",
- "serverid": server.id,
- "ownerid": server.owner.id,
- "prefix": "&"
- }
- connection.query("INSERT INTO servers SET ?", info, function(error) {
- if (error) {
- console.log(error);
- return;
- }
- console.log("Server Inserted!");
- })
- })
- bot.on("serverDeleted", function(server) {
- console.log("Attempting to remove " + server.name + " from the database!");
- connection.query("DELETE FROM servers WHERE serverid = '" + server.id + "'", function(error) {
- if (error) {
- console.log(error);
- return;
- }
- console.log("Server Removed!");
- })
- })
- bot.on("message", function(message) {
- if (!message.channel.isPrivate) {
- if (message.content === "ping") {
- bot.sendMessage(message, "Hello, pong! Your on server **" + message.channel.server.name + "**");
- }
- } else {
- if (message.content === "ping") {
- bot.sendMessage(message, "Hello, pong! Your on **PM**");
- }
- }
- });
- bot.loginWithToken("MTg4NDI0NzMzODgzMTA1Mjgy.CnEbsQ.PjRA3LFDk81GmRBqrUEPVoYKbV0");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement