xenoderf
xenoderf
DIAdiscord.js - Imagine an app
Created by xenoderf on 8/16/2023 in #djs-questions
Trying to create a game lobby of sorts
Is it possible to follow up an earlier interaction when another unrelated interaction happens?
7 replies
DIAdiscord.js - Imagine an app
Created by xenoderf on 8/16/2023 in #djs-questions
Trying to create a game lobby of sorts
But there is an interaction right? because the players would all have hit join so is it possible to somehow send a follow up?
7 replies
DIAdiscord.js - Imagine an app
Created by xenoderf on 8/16/2023 in #djs-questions
Trying to create a game lobby of sorts
const { ButtonInteraction } = require('discord.js')

const joinedPlayers = new Set();

module.exports = {
name: "interactionCreate",
/**
*
* @param {ButtonInteraction} interaction
*/
async execute(interaction) {
if (!interaction.isButton()) return;

const args = interaction.customId.split('_');
if (args[0] !== "begin") return;

const name = interaction.member.nickname;

switch (args[1]) {
case "join": {
//Add player to set of joined players, check if they are already joined
if (joinedPlayers.has(`${interaction.user.id}-${interaction.message.id}`)) {
return interaction.reply({content: "You already joined", ephemeral: true});
}
joinedPlayers.add(`${interaction.user.id}-${interaction.message.id}`);

console.log(joinedPlayers);

const beginEmbed = interaction.message.embeds[0];
if (!beginEmbed) {
return interaction.reply({content: "Unable to find poll embed", ephemeral: true});
}

const beginField = beginEmbed.fields[0];
const joinReply = "Successfully joined the game"

if (beginField.value == 'None') {
beginField.value = name;
} else {
beginField.value = beginField.value.concat(", ", name);
}

interaction.reply({content: joinReply, ephemeral: true});
interaction.message.edit({embeds: [beginEmbed]});
}
break;
case "start": {
//Start the game with players in set

}
break;
}


}
}
const { ButtonInteraction } = require('discord.js')

const joinedPlayers = new Set();

module.exports = {
name: "interactionCreate",
/**
*
* @param {ButtonInteraction} interaction
*/
async execute(interaction) {
if (!interaction.isButton()) return;

const args = interaction.customId.split('_');
if (args[0] !== "begin") return;

const name = interaction.member.nickname;

switch (args[1]) {
case "join": {
//Add player to set of joined players, check if they are already joined
if (joinedPlayers.has(`${interaction.user.id}-${interaction.message.id}`)) {
return interaction.reply({content: "You already joined", ephemeral: true});
}
joinedPlayers.add(`${interaction.user.id}-${interaction.message.id}`);

console.log(joinedPlayers);

const beginEmbed = interaction.message.embeds[0];
if (!beginEmbed) {
return interaction.reply({content: "Unable to find poll embed", ephemeral: true});
}

const beginField = beginEmbed.fields[0];
const joinReply = "Successfully joined the game"

if (beginField.value == 'None') {
beginField.value = name;
} else {
beginField.value = beginField.value.concat(", ", name);
}

interaction.reply({content: joinReply, ephemeral: true});
interaction.message.edit({embeds: [beginEmbed]});
}
break;
case "start": {
//Start the game with players in set

}
break;
}


}
}
7 replies
DIAdiscord.js - Imagine an app
Created by xenoderf on 8/16/2023 in #djs-questions
Trying to create a game lobby of sorts
node v16.14.0, discord.js v14.12.1
7 replies