RCON Response

I have a working chunk of code for RCON, but I can only get it to console log the command and the information. I have been trying to get it to output the information from the command to the Discord channel. Any help with this would be greatly appreciated. šŸ™‚
9 Replies
d.js toolkit
d.js toolkitā€¢12mo ago
ā€¢ What's your exact discord.js npm list discord.js and node node -v version? ā€¢ Post the full error stack trace, not just the top part! ā€¢ Show your code! ā€¢ Explain what exactly your issue is. ā€¢ Not a discord.js issue? Check out #useful-servers.
munxo
munxoā€¢12mo ago
conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response', function(str) {
console.log("Response: " + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});
conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response', function(str) {
console.log("Response: " + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});
Remote Connect, used for sending commands to a game server via a Discord Bot or something else.
d.js docs
d.js docsā€¢12mo ago
const channel = client.channels.cache.get("222086648706498562");
const channel = guild.channels.cache.find(channel => channel.name === "general");
const channel = client.channels.cache.get("222086648706498562");
const channel = guild.channels.cache.find(channel => channel.name === "general");
- Caches in discord.js are Collections which extend the native Map structure. - learn more
munxo
munxoā€¢12mo ago
Yeah, my bot is active and I have an
interaction.reply(`**Server ${server}** ${command}`);
interaction.reply(`**Server ${server}** ${command}`);
with the correct const for this to work, but I can only get it to log in my VS Code
munxo
munxoā€¢12mo ago
If I input this
munxo
munxoā€¢12mo ago
I get this in VS Code
munxo
munxoā€¢12mo ago
I want that "Response:" to be sent back into the channel either via .reply or something. I just haven't been able to do it. I have no other ideas on how to and I'm sure it's rather simple and I'm over complicating things.
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'rcon') {

const conn = new Rcon(process.env.HOST_IP, process.env.HOST_PORT, process.env.HOST_PASS);

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response', function(str) {
console.log("Response: " + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();

const server = interaction.options.get('server').value;
const command = interaction.options.get('command').value;

interaction.reply(`**Server ${server}** ${command}`);
}});
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'rcon') {

const conn = new Rcon(process.env.HOST_IP, process.env.HOST_PORT, process.env.HOST_PASS);

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response', function(str) {
console.log("Response: " + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();

const server = interaction.options.get('server').value;
const command = interaction.options.get('command').value;

interaction.reply(`**Server ${server}** ${command}`);
}});
Yep, both server and command are defined. The commands work in game and everything, but I just need the command info to be spit back out into the Discord. So if I do a .followUp( ), within the parentheses I should put? I'm using this,
const command = interaction.options.get('command').value;
const command = interaction.options.get('command').value;
to grab the content from the slash command option. @qjuh I have this now:
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'rcon') {

const conn = new Rcon(process.env.HOST_IP, process.env.HOST_PORT, process.env.HOST_PASS);
const server = interaction.options.get('server').value;
const command = interaction.options.get('command').value;

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response',
function(str) {
console.log("Response: " + str);
interaction.reply(`**Server ${server}** ` + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();
}});
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'rcon') {

const conn = new Rcon(process.env.HOST_IP, process.env.HOST_PORT, process.env.HOST_PASS);
const server = interaction.options.get('server').value;
const command = interaction.options.get('command').value;

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/${command}`);
}).on('response',
function(str) {
console.log("Response: " + str);
interaction.reply(`**Server ${server}** ` + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();
}});
munxo
munxoā€¢12mo ago
It logs the command in VS Code and send this as a reply
munxo
munxoā€¢12mo ago
Nothing, just wanted to share the code that worked. That should be all until next time. šŸ™‚ Thank you for the help.