Skip to content

Instantly share code, notes, and snippets.

@w3barsi
Created August 2, 2020 15:51
Show Gist options
  • Save w3barsi/9a6c438f1a3ca5c51150d2e7f2b54cd5 to your computer and use it in GitHub Desktop.
Save w3barsi/9a6c438f1a3ca5c51150d2e7f2b54cd5 to your computer and use it in GitHub Desktop.
const { prefix: PRE, token: TOKEN } = require('./config.json');
const discord = require('discord.js');
const mineflayer = require('mineflayer');
const client = new discord.Client();
let botList = new Map();
let channel;
client.once('ready', () => {
console.log('Bot online!');
console.log('/bot new <host> <username>');
console.log('/bot del <username>');
});
client.on('message', (message) => {
if (!message.content.startsWith(PRE) || message.author.bot) return;
const args = message.content.slice(PRE.length).split(' ');
const commandName = args.shift().toLowerCase();
channel = message.channel;
if (commandName === 'bot') {
if (!message.member.roles.cache.has('735080627652526130'))
return message.channel.send(
`Sorry, only 'The Boys' can use this command`
);
switch (args[0]) {
case 'new':
startCrackedBot(args.slice(1));
break;
case 'del':
deleteBot(args[1]);
break;
case 'list':
displayBotList();
break;
}
}
});
client.login(TOKEN);
async function startCrackedBot(args) {
if (args.length < 2)
return channel.send(
`Too few arguments to start a bot '/bot new <host> <username>'`
);
let bot = await mineflayer.createBot({
host: args[0],
username: args[1],
});
console.log(`Bot ${args[1]} has been created`);
channel.send(`Bot ${args[1]} has been created`);
botList.set(args[1], bot);
}
function deleteBot(name) {
let bot = botList.get(name);
if (!bot) {
console.log(`No such bot exists`);
return channel.send(`No such bot exists`);
}
bot.end();
channel.send(`Bot ${name} has been stopped`);
console.log(`Bot ${name} has been stopped`);
botList.delete(name);
channel = null;
}
function displayBotList() {
let b = '';
for (let key of botList.keys()) {
b += `${key}\n`;
}
if (!b) return channel.send('No bots are alive');
console.log(b);
channel.send(`\`\`\`${b}\`\`\``);
}
@setiawanjemy88
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment