Discordbot.js (sockets and bridge)

I'm creating a bot to communicate between discord and a game made in C++. The "bridge" is created and working... But I'm having problems sending messages with utf8 accents
10 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Agadê, o sumido (HD Scripts)
discord.js └── discord.js@11.6.4 node -v v16.14.2 when send from discord to game, words with accent, have a bug on game letters with utf8 no working from game to discord, i solve by using "latin1"... but discord > game don't work
/* Send from discord to game */
client.on("message", 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`);
};
})
/* Send from discord to game */
client.on("message", 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`);
};
})
this part is responsable to send a message from discord to game
Squid
Squid2y ago
We only offer support for discord.js problems that use v13 and above
Agadê, o sumido (HD Scripts)
discord.js@11.6.4
Squid
Squid2y ago
11 < 13
Agadê, o sumido (HD Scripts)
ok, i upgrade to
discord.js@14.7.1
discord.js@14.7.1
code updated too
const net = require('net');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
let sockets = [];

/* Status when bot starts */
const status = [
'🥇 !help para ajuda',
];

/* Set status and message to bot when online */
client.on("ready", () => {
client.user.setActivity(status[0]);
client.user.setStatus('online');
});

/* receive from game to discord */
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);
}).listen(1337, "127.0.0.1");

/* Send from discord to game */
client.on("messageCreate", 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`);
};
})

//Token bot
client.login('TOKEN HERE');
const net = require('net');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
let sockets = [];

/* Status when bot starts */
const status = [
'🥇 !help para ajuda',
];

/* Set status and message to bot when online */
client.on("ready", () => {
client.user.setActivity(status[0]);
client.user.setStatus('online');
});

/* receive from game to discord */
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);
}).listen(1337, "127.0.0.1");

/* Send from discord to game */
client.on("messageCreate", 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`);
};
})

//Token bot
client.login('TOKEN HERE');
FeelsBadMan
sockets[0].setEncoding("latin1").write(`${msg.author.username} : ${msg.content}\0`);
sockets[0].setEncoding("latin1").write(`${msg.author.username} : ${msg.content}\0`);
i'm trying this... not working too
Agadê, o sumido (HD Scripts)
because this...
Agadê, o sumido (HD Scripts)
messages leaving discord for the game, undergo changes how to transform to compatible? hi, sorry for late I believe the game is latin1 however, when the message leaves the game for node.js, the letters do not come out as desired how to easily convert? i found this:
var net = require('net');
var Iconv = require('iconv').Iconv;
var server = net.createServer(function(conn) {
var iconv = new Iconv('latin1', 'utf-8');
conn.pipe(iconv).pipe(conn);
});
server.listen(8000);
console.log('Listening on tcp://0.0.0.0:8000/');
var net = require('net');
var Iconv = require('iconv').Iconv;
var server = net.createServer(function(conn) {
var iconv = new Iconv('latin1', 'utf-8');
conn.pipe(iconv).pipe(conn);
});
server.listen(8000);
console.log('Listening on tcp://0.0.0.0:8000/');
Agadê, o sumido (HD Scripts)
GitHub
GitHub - bnoordhuis/node-iconv: node.js iconv bindings - text recod...
node.js iconv bindings - text recoding for fun and profit! - GitHub - bnoordhuis/node-iconv: node.js iconv bindings - text recoding for fun and profit!
Agadê, o sumido (HD Scripts)
my code:
/* receive from game to discord */
var server = net.createServer(socket => {
//socket.setEncoding("latin1");
var iconv = new Iconv('latin1', 'utf-8');
socket.pipe(iconv).pipe(socket);
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");
/* receive from game to discord */
var server = net.createServer(socket => {
//socket.setEncoding("latin1");
var iconv = new Iconv('latin1', 'utf-8');
socket.pipe(iconv).pipe(socket);
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");
i'm testing... but have error