if (process.argv.length < 6 || process.argv.length > 8) {
console.log('Usage : node discord.js <discord bot token> <channel id> <host> <port> [<name>] [<auth>]')
process.exit(1)
}
const { Client, GatewayIntentBits } = require('discord.js')
const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits
let channel = process.argv[3]
const token = process.argv[2]
const client = new Client({ intents: [Guilds, GuildMessages, MessageContent] })
client.login(token)
const mineflayer = require('mineflayer')
const options = {
host: process.argv[4],
port: parseInt(process.argv[5]),
username: process.argv[6] || 'discord',
auth: process.argv[7] || 'offline'
}
const bot = mineflayer.createBot(options)
bot.on('spawn', () => {
console.log(`Mineflayer bot logged in as ${bot.username}`)
})
client.once('ready', (c) => {
console.log(`Discord bot logged in as ${c.user.tag}`)
channel = client.channels.cache.get(channel)
if (!channel) {
console.log(`I could not find the channel (${process.argv[3]})!`)
console.log('Usage : node discord.js <discord bot token> <channel id> <host> <port> [<name>] [<auth>]')
process.exit(1)
}
})
client.on('messageCreate', (message) => {
if (message.channel.id !== channel.id) return
if (message.author.id === client.user.id) return
bot.chat(`${message.author.username}: ${message.content}`)
})
bot.on('chat', (username, message) => {
if (username === bot.username) return
channel.send(`${username}: ${message}`)
})