SuitSnap
SuitSnap
DIAdiscord.js - Imagine an app
Created by SuitSnap on 7/28/2023 in #djs-questions
Channel Select Menu doesn't seem to function?
Why is this erroring:
const addChannelSelectMenu = new ChannelSelectMenuBuilder({
custom_id: `add_team_channels`,
})
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
.setMinValues(1)
.setPlaceholder(`Select team channels!`);
const addChannelSelectMenu = new ChannelSelectMenuBuilder({
custom_id: `add_team_channels`,
})
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildVoice)
.setMinValues(1)
.setPlaceholder(`Select team channels!`);
Erroring with:
Error: DiscordAPIError[50035]: Invalid Form Body
data.components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1,).
Error: DiscordAPIError[50035]: Invalid Form Body
data.components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1,).
?
12 replies
DIAdiscord.js - Imagine an app
Created by SuitSnap on 5/29/2023 in #djs-questions
Limit reactions to one per message
discord.js :[email protected] Node: v20.2.0 I'm trying to make a poll bot based on reactions and I'm trying to limit reactions so that each user can only be reacted to one emoji at a time. Currently I have a system that checks if a user is already reacted and if so, removes and new reactions until they remove their original reaction but I'm wondering if a system that would remove the old reaction is instead possible? This is the current system I have for the limiting.
interaction.client.on("messageReactionAdd", async (reaction, user) => {
//Check that the reaction is not a partial
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();

/*Check if:
the reactor is not a bot,
if the reaction is in a DM,
if the message reacted to is the poll for this interaction,
if the poll has ended and return if any are true */
if (
user.bot ||
!reaction.message.guild ||
pollMessage.id != reaction.message.id ||
timedOut
)
return;

//No new reactions emojis can be added
if (!reactionEmojis.includes(reaction._emoji.toString())) {
reaction.users.remove(user.id).catch(console.error);
return;
}

const { message } = reaction;
let member = reaction.message.guild.members.cache.get(user.id);

//Limit reactions to member if need be
if (roleID != null) {
if (!member.roles.cache.has(roleID.value)) {
reaction.users.remove(user.id).catch(console.error);
return;
}
}

if (!reactionCount.get(message))
reactionCount.set(message, new Collection());
const userCount = reactionCount.get(message);
userCount.set(user, (userCount.get(user) || 0) + 1);

if (userCount.get(user) > 1) {
reaction.users.remove(user);
return;
}
const pollMessageString = await generatePollBars(
pollMessage,
votingOptions
);
pollEmbed.setDescription(pollMessageString);
await pollMessage.edit({ embeds: [pollEmbed] });
});

interaction.client.on("messageReactionRemove", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (
user.bot ||
!reaction.message.guild ||
pollMessage.id != reaction.message.id ||
timedOut
)
return;

const { message } = reaction;
const userCount = reactionCount.get(message);
// subtract 1 from user's reaction count
try {
userCount.set(user, reactionCount.get(message).get(user) - 1);
} catch (TypeError) {}
const pollMessageString = await generatePollBars(
pollMessage,
votingOptions
);
pollEmbed.setDescription(pollMessageString);
await pollMessage.edit({ embeds: [pollEmbed] });
});
interaction.client.on("messageReactionAdd", async (reaction, user) => {
//Check that the reaction is not a partial
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();

/*Check if:
the reactor is not a bot,
if the reaction is in a DM,
if the message reacted to is the poll for this interaction,
if the poll has ended and return if any are true */
if (
user.bot ||
!reaction.message.guild ||
pollMessage.id != reaction.message.id ||
timedOut
)
return;

//No new reactions emojis can be added
if (!reactionEmojis.includes(reaction._emoji.toString())) {
reaction.users.remove(user.id).catch(console.error);
return;
}

const { message } = reaction;
let member = reaction.message.guild.members.cache.get(user.id);

//Limit reactions to member if need be
if (roleID != null) {
if (!member.roles.cache.has(roleID.value)) {
reaction.users.remove(user.id).catch(console.error);
return;
}
}

if (!reactionCount.get(message))
reactionCount.set(message, new Collection());
const userCount = reactionCount.get(message);
userCount.set(user, (userCount.get(user) || 0) + 1);

if (userCount.get(user) > 1) {
reaction.users.remove(user);
return;
}
const pollMessageString = await generatePollBars(
pollMessage,
votingOptions
);
pollEmbed.setDescription(pollMessageString);
await pollMessage.edit({ embeds: [pollEmbed] });
});

interaction.client.on("messageReactionRemove", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (
user.bot ||
!reaction.message.guild ||
pollMessage.id != reaction.message.id ||
timedOut
)
return;

const { message } = reaction;
const userCount = reactionCount.get(message);
// subtract 1 from user's reaction count
try {
userCount.set(user, reactionCount.get(message).get(user) - 1);
} catch (TypeError) {}
const pollMessageString = await generatePollBars(
pollMessage,
votingOptions
);
pollEmbed.setDescription(pollMessageString);
await pollMessage.edit({ embeds: [pollEmbed] });
});
3 replies