meap moop
DIAdiscord.js - Imagine an app
•Created by meap moop on 12/8/2023 in #djs-questions
"this interaction failed"
const seeRooms = async (interaction, embed, page, room_names, channel_id, room_pictures, count) => {
embed.setAuthor({ name: `Please select the room you are looking for!` })
.setTitle(`Room Name: ${room_names[page-1]}`)
.setFooter({ text:`Page ${page}/${room_names.length}` })
.setImage(room_pictures[page-1])
const left_button = new discord.ButtonBuilder()
.setCustomId('left')
.setEmoji('◀')
.setStyle(discord.ButtonStyle.Secondary)
const right_button = new discord.ButtonBuilder()
.setCustomId('right')
.setEmoji('▶')
.setStyle(discord.ButtonStyle.Secondary)
const select_button = new discord.ButtonBuilder()
.setCustomId('select')
.setEmoji('⏹')
.setStyle(discord.ButtonStyle.Secondary)
if(page == 1){
left_button.setDisabled(true)
}
if(page == room_names.length){
right_button.setDisabled(true)
}
const buttonsRow = new discord.ActionRowBuilder()
.addComponents(left_button, select_button, right_button)
var msg
if(interaction.deffered || interaction.replied){
msg = await interaction.editReply({ embeds: [embed], components: [buttonsRow] })
}
else{
msg = await interaction.update({ embeds: [embed], components: [buttonsRow] })
}
const collector = msg.createMessageComponentCollector({ componentType: discord.ComponentType.Button, time: 6*1000*60 })
collector.on('collect', async i => {
switch(i.customId){
case 'left':
page -= 1
count+=1
seeRooms(interaction, embed, page, room_names, channel_id, room_pictures, count)
break
case 'right':
page +=1
count+=1
seeRooms(interaction, embed, page, room_names, channel_id, room_pictures, count)
break
case 'select':
console.log('select')
break
}
})
}
const seeRooms = async (interaction, embed, page, room_names, channel_id, room_pictures, count) => {
embed.setAuthor({ name: `Please select the room you are looking for!` })
.setTitle(`Room Name: ${room_names[page-1]}`)
.setFooter({ text:`Page ${page}/${room_names.length}` })
.setImage(room_pictures[page-1])
const left_button = new discord.ButtonBuilder()
.setCustomId('left')
.setEmoji('◀')
.setStyle(discord.ButtonStyle.Secondary)
const right_button = new discord.ButtonBuilder()
.setCustomId('right')
.setEmoji('▶')
.setStyle(discord.ButtonStyle.Secondary)
const select_button = new discord.ButtonBuilder()
.setCustomId('select')
.setEmoji('⏹')
.setStyle(discord.ButtonStyle.Secondary)
if(page == 1){
left_button.setDisabled(true)
}
if(page == room_names.length){
right_button.setDisabled(true)
}
const buttonsRow = new discord.ActionRowBuilder()
.addComponents(left_button, select_button, right_button)
var msg
if(interaction.deffered || interaction.replied){
msg = await interaction.editReply({ embeds: [embed], components: [buttonsRow] })
}
else{
msg = await interaction.update({ embeds: [embed], components: [buttonsRow] })
}
const collector = msg.createMessageComponentCollector({ componentType: discord.ComponentType.Button, time: 6*1000*60 })
collector.on('collect', async i => {
switch(i.customId){
case 'left':
page -= 1
count+=1
seeRooms(interaction, embed, page, room_names, channel_id, room_pictures, count)
break
case 'right':
page +=1
count+=1
seeRooms(interaction, embed, page, room_names, channel_id, room_pictures, count)
break
case 'select':
console.log('select')
break
}
})
}
10 replies