Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. const { Client } = require('discord.js');
  2. const bot = new Client();
  3. const cfg = require('./config.json');
  4.  
  5. var status = "In Raz's Minecraft Server";
  6. var request = require('request');
  7. var mcCommand = '/Minecraft'; // Command for triggering
  8. var mcIP = '77.125.40.159'; // Your MC server IP
  9. var mcPort = 25565; // Your MC server port
  10.  
  11. var mc = require('minecraft-protocol');
  12. var client = mc.createClient({
  13. host: "localhost", // optional
  14. port: 25565, // optional
  15. username: "raznerd@gmail.com",
  16. password: "oofity oof",
  17. });
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. bot.on('ready', () => {
  26. console.log(`Connected to ${bot.guilds.size} servers`);
  27. console.log(`Logged in as ${bot.user.tag} (${bot.user.id})`);
  28. bot.user.setActivity(status, { type: 'PLAYING' })
  29. .then(presence => console.log(status))
  30. .catch(console.error);
  31. });
  32.  
  33. bot.on('message' , msg => {
  34. if (msg.author.client || !msg.content.startsWith(cfg.prefix)) return;
  35. const command = args.shift();
  36.  
  37. if(command === 'hi') {
  38. msg.channel.send('hi');
  39. }
  40. if(command === 'test') {
  41. MSMediaK
  42. }
  43.  
  44.  
  45. if(command === 'sendmsg') {
  46. let oof = args.join(" ").slice(22);
  47. if(!sendmsg) return msg.channel.send("Please put in text to send");
  48. msg.channel.send(`This is the message that you sent: ${oof}`);
  49. client.write('chat', {message: `User ${user} has sent the following message: ${oof}`});
  50. }
  51.  
  52.  
  53.  
  54. });
  55.  
  56. bot.on('message', function(message){
  57.  
  58. if(message.content === 'test') {
  59. message.channel.send('it works :D')
  60. }
  61.  
  62. if (message.content === 'server') {
  63. var url = 'http://mcapi.us/server/status?ip=' + mcIP + '&port=' + mcPort;
  64. request(url, function(err, response, body) {
  65. if(err) {
  66. console.log(err);
  67. return message.channel.send('Error getting Minecraft server status...');
  68. }
  69. body = JSON.parse(body);
  70. var status = '*Minecraft server is currently offline*';
  71. if(body.online) {
  72. status = '**Minecraft** server is **online** - ';
  73. if(body.players.now) {
  74. status += '**' + body.players.now + '** people are playing!';
  75. } else {
  76. status += '*Nobody is playing!*';
  77. }
  78. }
  79. message.channel.send(status);
  80. });
  81. }
  82.  
  83. });
  84.  
  85. bot.on('chat', function(packet) {
  86. // Listen for chat messages and echo them back.
  87. var jsonMsg = JSON.parse(packet.message);
  88. if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
  89. var username = jsonMsg.with[0].text;
  90. var msg = jsonMsg.with[1];
  91. if(username === client.username) return;
  92. client.write('chat', {message: msg});
  93. }
  94. });
  95.  
  96.  
  97.  
  98. bot.login(cfg.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement