Shards Interaction

Hello ! I have some troubles with sharding specifically with interactions between shards, i wonder if it's possible to send a message with buttons to a server present on an other shard and then get the interaction response ? I know .broadcastEval() exist but the data are serialized so it's not really the solution... discord.js version : 13.7.0 node version : 16.14.2
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Nelvazz
Nelvazz2y ago
I've done something like this:
const Embed = new MessageEmbed()
.setDescription('testing shards broadcastEval')

const Buttons = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('buttonid')
.setEmoji('❗')
.setStyle('SECONDARY'),
)

const msg = await bot.shard.broadcastEval(async (c, embed, buttons) => {
const channel = await c.channels.cache.get('id');
if (channel) {
let m = await channel.send({ embeds: [embed.embed[0]], components: embed.buttons })
const collector = m.createMessageComponentCollector({ time: 30000 })

collector.on('collect', async(i) => {
console.log('user interacted')
})
}
}, { context: { embed: [Embed], buttons: [Buttons] } })
const Embed = new MessageEmbed()
.setDescription('testing shards broadcastEval')

const Buttons = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('buttonid')
.setEmoji('❗')
.setStyle('SECONDARY'),
)

const msg = await bot.shard.broadcastEval(async (c, embed, buttons) => {
const channel = await c.channels.cache.get('id');
if (channel) {
let m = await channel.send({ embeds: [embed.embed[0]], components: embed.buttons })
const collector = m.createMessageComponentCollector({ time: 30000 })

collector.on('collect', async(i) => {
console.log('user interacted')
})
}
}, { context: { embed: [Embed], buttons: [Buttons] } })
But now if i want to send an other embed from the interaction do i really need to define MessageEmbed again ?
const msg = await bot.shard.broadcastEval(async (c, embed, buttons) => {
const { MessageEmbed } = require('discord.js') // Do i really need to add this for every discord.js functionnality ?
const channel = await c.channels.cache.get('id');
if (channel) {
let m = await channel.send({ embeds: [embed.embed[0]], components: embed.buttons })
const collector = m.createMessageComponentCollector({ time: 30000 })

collector.on('collect', async(i) => {
switch(i.id) {
case 'buttonid':
const embed2 = new MessageEmbed()
.setDescription('another embed')
i.reply({ embeds: [embed2] })
break
}
})
}
}, { context: { embed: [Embed], buttons: [Buttons] } })
const msg = await bot.shard.broadcastEval(async (c, embed, buttons) => {
const { MessageEmbed } = require('discord.js') // Do i really need to add this for every discord.js functionnality ?
const channel = await c.channels.cache.get('id');
if (channel) {
let m = await channel.send({ embeds: [embed.embed[0]], components: embed.buttons })
const collector = m.createMessageComponentCollector({ time: 30000 })

collector.on('collect', async(i) => {
switch(i.id) {
case 'buttonid':
const embed2 = new MessageEmbed()
.setDescription('another embed')
i.reply({ embeds: [embed2] })
break
}
})
}
}, { context: { embed: [Embed], buttons: [Buttons] } })
monbrey
monbrey2y ago
Thats how eval works, yeah, You need to require things you want it to use inside it's context