hdscripts
New Coder
Hi guys.
My code consists of: send a discord message to the game, and vice versa...
But I'm having some problems with "encoding" from UTF-8 to Unicode.
Here's a video that explains more of what I want to do:
Message received from game -> discord OK
Message received from discord -> game FAIL (with encoding)
My code:
Somebody can help me to do this?
My code consists of: send a discord message to the game, and vice versa...
But I'm having some problems with "encoding" from UTF-8 to Unicode.
Here's a video that explains more of what I want to do:

Message received from game -> discord OK
Message received from discord -> game FAIL (with encoding)
My code:
JavaScript:
/*
Discord bot v1.0 using node.js to create a "bridge" between C++ and Discord.
Created by @Normynator, and upgraded by HD Scripts 2023
*/
const net = require('net');
const { Client, GatewayIntentBits, Collection, InteractionType } = require('discord.js');
const { token } = require('./config.json');
var Iconv = require('iconv').Iconv;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildIntegrations
]
});
module.exports = client
let sockets = [];
/* Status when bot starts */
const status = [
'🥇 !help to help',
];
/* Set status and message to bot when online */
client.on('ready', () => {
client.user.setActivity(status[0]);
client.user.setStatus('online');
console.log(`Ready! Logged in as ${client.user.username}`);
});
/* receive from game to discord */
var server = net.createServer(socket => {
socket.setEncoding("latin1");
socket.on("data", (msg) => {
client.channels.cache.get('1049483595061932102').send(msg).then(() => {
console.log('Message online sent');
console.log(msg);
}).catch(err => {
console.log(err);
});
})
sockets.push(socket);
})
server.listen(1337, "127.0.0.1");
/* Send from discord to game */
client.on("messageCreate", msg => {
//var iconv = new Iconv('utf-8', 'ISO-8859-1');
//var buffer = iconv.convert(msg);
if (msg.channel.name === "status-servidor" && !msg.author.bot) {
console.log(msg.author.username, msg.content);
sockets[0].write(`${msg.author.username} : ${msg.content}\0`);
};
})
client.slashCommands = new Collection()
require('./Handler')(client)
// Register slashcommands
client.on('interactionCreate', (interaction) => {
if(interaction.type === InteractionType.ApplicationCommand){
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd) return interaction.reply(`Error`);
interaction["member"] = interaction.guild.members.cache.get(interaction.user.id);
cmd.run(client, interaction)
}
})
//Token bot
client.login(token);
Somebody can help me to do this?