Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client } = require('discord.js');
- const bot = new Client();
- const cfg = require('./config.json');
- var status = "In Raz's Minecraft Server";
- var request = require('request');
- var mcCommand = '/Minecraft'; // Command for triggering
- var mcIP = '77.125.40.159'; // Your MC server IP
- var mcPort = 25565; // Your MC server port
- var mc = require('minecraft-protocol');
- var client = mc.createClient({
- host: "localhost", // optional
- port: 25565, // optional
- username: "raznerd@gmail.com",
- password: "oofity oof",
- });
- bot.on('ready', () => {
- console.log(`Connected to ${bot.guilds.size} servers`);
- console.log(`Logged in as ${bot.user.tag} (${bot.user.id})`);
- bot.user.setActivity(status, { type: 'PLAYING' })
- .then(presence => console.log(status))
- .catch(console.error);
- });
- bot.on('message' , msg => {
- if (msg.author.client || !msg.content.startsWith(cfg.prefix)) return;
- const command = args.shift();
- if(command === 'hi') {
- msg.channel.send('hi');
- }
- if(command === 'test') {
- MSMediaK
- }
- if(command === 'sendmsg') {
- let oof = args.join(" ").slice(22);
- if(!sendmsg) return msg.channel.send("Please put in text to send");
- msg.channel.send(`This is the message that you sent: ${oof}`);
- client.write('chat', {message: `User ${user} has sent the following message: ${oof}`});
- }
- });
- bot.on('message', function(message){
- if(message.content === 'test') {
- message.channel.send('it works :D')
- }
- if (message.content === 'server') {
- var url = 'http://mcapi.us/server/status?ip=' + mcIP + '&port=' + mcPort;
- request(url, function(err, response, body) {
- if(err) {
- console.log(err);
- return message.channel.send('Error getting Minecraft server status...');
- }
- body = JSON.parse(body);
- var status = '*Minecraft server is currently offline*';
- if(body.online) {
- status = '**Minecraft** server is **online** - ';
- if(body.players.now) {
- status += '**' + body.players.now + '** people are playing!';
- } else {
- status += '*Nobody is playing!*';
- }
- }
- message.channel.send(status);
- });
- }
- });
- bot.on('chat', function(packet) {
- // Listen for chat messages and echo them back.
- var jsonMsg = JSON.parse(packet.message);
- if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
- var username = jsonMsg.with[0].text;
- var msg = jsonMsg.with[1];
- if(username === client.username) return;
- client.write('chat', {message: msg});
- }
- });
- bot.login(cfg.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement