Larsenv
Larsenv
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
@d4isdavid sorry to bother but you there?
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
I know
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
then lots of people started testing it
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
michael mjd created a video on it
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
?
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
you know why it became popular
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
really didn't see how many people had been adding the bot to their discord
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
I didn't know
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
not very fun when my bot's in over 2500 discord and it break
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
thank you for helping thus far 🙂
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
🤔
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
Uncaught Exception: TypeError: process.send is not a function
at Client.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/discord.js/src/sharding/ShardClientUtil.js:43:19)
at Client.emit (node:events:527:28)
at WebSocketManager.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/discord.js/src/client/websocket/WebSocketManager.js:270:19)
at WebSocketManager.emit (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@vladfrangu/async_event_emitter/dist/index.js:290:37)
at WebSocketShard.onClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@discordjs/ws/dist/index.js:1006:10)
at WebSocket.emit (node:events:527:28)
at WebSocket.emitClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/ws/lib/websocket.js:258:10)
at TLSSocket.socketOnClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/ws/lib/websocket.js:1264:15)
Uncaught Exception: TypeError: process.send is not a function
at Client.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/discord.js/src/sharding/ShardClientUtil.js:43:19)
at Client.emit (node:events:527:28)
at WebSocketManager.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/discord.js/src/client/websocket/WebSocketManager.js:270:19)
at WebSocketManager.emit (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@vladfrangu/async_event_emitter/dist/index.js:290:37)
at WebSocketShard.onClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/@discordjs/ws/dist/index.js:1006:10)
at WebSocket.emit (node:events:527:28)
at WebSocket.emitClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/ws/lib/websocket.js:258:10)
at TLSSocket.socketOnClose (/var/www/rc24/discross.rc24.xyz/public_html/node_modules/ws/lib/websocket.js:1264:15)
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
done
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
would moving the code over to be on shard.js help?
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
what confuses me's that looking into example code each has a client
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
you know what I can do to have it remedied?
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
sorry I thought that I sent that
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
const fs = require('fs')
const Discord = require('discord.js')
const auth = require('./authentication.js')
const connectionHandler = require('./connectionHandler.js')

const cachelength = 100 // Length of message history

const msghistory = {}
const client = new Discord.Client({ partials: [], intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.MessageContent] }) // Allows me to recieve "uncached" (actually manually cached by me) message events

// setInterval(function () { // TODO: See if this is needed
// client.user.setActivity('for people at https://discross.rc24.xyz/', { type: 'WATCHING' })
// }, 20000)

// https://stackoverflow.com/questions/1967119/why-does-javascript-replace-only-first-instance-when-using-replace

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
// console.log(client.channels.array());
})

client.on('messageCreate', async function (msg) {
if (msghistory[msg.channel.id] && !(msghistory[msg.channel.id].get(msg.id))) {
msghistory[msg.channel.id].set(msg.id, msg)

console.log(msghistory[msg.channel.id].length);

if (msghistory[msg.channel.id].length > cachelength) {
msghistory[msg.channel.id] = msghistory[msg.channel.id].slice(msghistory[msg.channel.id].length - (cachelength + 1), msghistory[msg.channel.id].length) // Limit the length of the cache to 50 messages
}
}

// console.log(msghistory[msg.channel.id.toString()].length);
if (msg.content === '^connect') {
if (msg.webhookID) {
msg.reply("you're already using Discross!")
} else {
msg.author.send('Verification code:\n`' + (await auth.createVerificationCode(msg.author.id)) + '`')
msg.reply('you have been sent a direct message with your verification code.')
}
}

// TODO: Do properly
connectionHandler.sendToAll(msg.content, msg.channel.id)
})

// client.on('messageDelete

exports.startBot = async function () {
client.login(fs.readFileSync('secrets/token.txt', 'utf-8').replace('\n', ''))
}

exports.addToCache = function (msg) {
if (msghistory[msg.channel.id]) {
msghistory[msg.channel.id].set(msg.id, msg)
}
}

exports.getHistoryCached = async function (chnl) {
if (!chnl.id) {
chnl = client.channels.get(chnl)
}
if (!msghistory[chnl.id]) {
const messagearray = await chnl.messages.fetch({ limit: cachelength })
msghistory[chnl.id] = messagearray.sort((messageA, messageB) => messageA.createdTimestamp - messageB.createdTimestamp)
}
return Array.from(msghistory[chnl.id].values())
}

exports.client = client
const fs = require('fs')
const Discord = require('discord.js')
const auth = require('./authentication.js')
const connectionHandler = require('./connectionHandler.js')

const cachelength = 100 // Length of message history

const msghistory = {}
const client = new Discord.Client({ partials: [], intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.MessageContent] }) // Allows me to recieve "uncached" (actually manually cached by me) message events

// setInterval(function () { // TODO: See if this is needed
// client.user.setActivity('for people at https://discross.rc24.xyz/', { type: 'WATCHING' })
// }, 20000)

// https://stackoverflow.com/questions/1967119/why-does-javascript-replace-only-first-instance-when-using-replace

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
// console.log(client.channels.array());
})

client.on('messageCreate', async function (msg) {
if (msghistory[msg.channel.id] && !(msghistory[msg.channel.id].get(msg.id))) {
msghistory[msg.channel.id].set(msg.id, msg)

console.log(msghistory[msg.channel.id].length);

if (msghistory[msg.channel.id].length > cachelength) {
msghistory[msg.channel.id] = msghistory[msg.channel.id].slice(msghistory[msg.channel.id].length - (cachelength + 1), msghistory[msg.channel.id].length) // Limit the length of the cache to 50 messages
}
}

// console.log(msghistory[msg.channel.id.toString()].length);
if (msg.content === '^connect') {
if (msg.webhookID) {
msg.reply("you're already using Discross!")
} else {
msg.author.send('Verification code:\n`' + (await auth.createVerificationCode(msg.author.id)) + '`')
msg.reply('you have been sent a direct message with your verification code.')
}
}

// TODO: Do properly
connectionHandler.sendToAll(msg.content, msg.channel.id)
})

// client.on('messageDelete

exports.startBot = async function () {
client.login(fs.readFileSync('secrets/token.txt', 'utf-8').replace('\n', ''))
}

exports.addToCache = function (msg) {
if (msghistory[msg.channel.id]) {
msghistory[msg.channel.id].set(msg.id, msg)
}
}

exports.getHistoryCached = async function (chnl) {
if (!chnl.id) {
chnl = client.channels.get(chnl)
}
if (!msghistory[chnl.id]) {
const messagearray = await chnl.messages.fetch({ limit: cachelength })
msghistory[chnl.id] = messagearray.sort((messageA, messageB) => messageA.createdTimestamp - messageB.createdTimestamp)
}
return Array.from(msghistory[chnl.id].values())
}

exports.client = client
184 replies
DIAdiscord.js - Imagine an app
Created by Larsenv on 6/26/2023 in #djs-questions
Sharding is Required | Bot doesn't respond
change it to do?
184 replies