scotty
scotty
DIAdiscord.js - Imagine a boo! 👻
Created by scotty on 7/18/2023 in #djs-questions
Bot not editing embed as expected
const existingMessages = await dchannel.messages.fetch({ limit: 1 });
const existingMessage = existingMessages
?.filter((msg) => msg.author.bot && msg.author.id === interaction.client.user.id)
.first();

if (existingMessage) {
if (existingMessage.embeds.length > 0) {
const existingEmbed = existingMessage.embeds[0];
const updatedEmbed = new EmbedBuilder(existingEmbed)
.addFields({
name: displayName || "Unknown User",
value: formattedDate,
});
await existingMessage.edit({ embeds: [updatedEmbed] });
}
} else {
const existingMessages = await dchannel.messages.fetch({ limit: 1 });
const existingMessage = existingMessages
?.filter((msg) => msg.author.bot && msg.author.id === interaction.client.user.id)
.first();

if (existingMessage) {
if (existingMessage.embeds.length > 0) {
const existingEmbed = existingMessage.embeds[0];
const updatedEmbed = new EmbedBuilder(existingEmbed)
.addFields({
name: displayName || "Unknown User",
value: formattedDate,
});
await existingMessage.edit({ embeds: [updatedEmbed] });
}
} else {
The bot should edit the original embed if there is one with the new data from the command, which it does successfully. However, if there is a message sent in the channel from another user (not the bot) which is more recent than the embed, instead of updating the original embed it creates a new one - which it should only do if there's no embed in the channel at all.
4 replies
DIAdiscord.js - Imagine a boo! 👻
Created by scotty on 6/10/2023 in #djs-questions
Detecting role removal
client.on('guildMemberUpdate', (oldMember, newMember) => {
const roleID = '899870393282752542';

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));

if (removedRoles.has(roleID)) {
console.log(`Role with ID ${roleID} was removed from ${oldMember.user.username}`);
}
});
client.on('guildMemberUpdate', (oldMember, newMember) => {
const roleID = '899870393282752542';

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));

if (removedRoles.has(roleID)) {
console.log(`Role with ID ${roleID} was removed from ${oldMember.user.username}`);
}
});
When role is removed, it should be logged in the console. However, it only works if the role i remove the role of myself, not if i remove it from someone else.
6 replies
DIAdiscord.js - Imagine a boo! 👻
Created by scotty on 6/10/2023 in #djs-questions
GuildMemberRemove not working
client.on(Events.GuildMemberRemove, async (member) => {
console.log(`GuildMemberRemove: ${member}`);
});
client.on(Events.GuildMemberRemove, async (member) => {
console.log(`GuildMemberRemove: ${member}`);
});
When the user leaves, it is not logged in the console. I feel like this should be really simple, yet I do't know why it isn't working
3 replies
DIAdiscord.js - Imagine a boo! 👻
Created by scotty on 5/10/2023 in #djs-questions
Trying to get users displayName, returning unknown user
3 replies
DIAdiscord.js - Imagine a boo! 👻
Created by scotty on 5/7/2023 in #djs-questions
Command not running despite meeting the requirements
.addStringOption((option) =>
option
.setName("rank")
.setDescription("Your respective rank")
.setRequired(true)
.addChoices(
{ name: "I", value: "I", roleId: "1051888647961575464" },
{ name: "C", value: "C", roleId: "989618534009159740" },
{ name: "E", value: "E", roleId: "989618534629916732" },
{ name: "RM", value: "RM", roleId: "1069139407204007986" },
{ name: "DD", value: "DD", roleId: "1056906050403573760" },
{ name: "BD", value: "BD", roleId: "899869665780719667" }
)
),

async execute(interaction) {
let user = interaction.options.getString("username");
let link = interaction.options.getString("link");
let division = interaction.options.getString("division");
let rank = interaction.options.getString("rank");


const selectedRank = interaction.options.get("rank");
const selectedRoleId = selectedRank.value.roleId;

if (!interaction.member.roles.cache.has(selectedRoleId)) {
await interaction.reply("You do not have permission to select that rank!");
return;
}
.addStringOption((option) =>
option
.setName("rank")
.setDescription("Your respective rank")
.setRequired(true)
.addChoices(
{ name: "I", value: "I", roleId: "1051888647961575464" },
{ name: "C", value: "C", roleId: "989618534009159740" },
{ name: "E", value: "E", roleId: "989618534629916732" },
{ name: "RM", value: "RM", roleId: "1069139407204007986" },
{ name: "DD", value: "DD", roleId: "1056906050403573760" },
{ name: "BD", value: "BD", roleId: "899869665780719667" }
)
),

async execute(interaction) {
let user = interaction.options.getString("username");
let link = interaction.options.getString("link");
let division = interaction.options.getString("division");
let rank = interaction.options.getString("rank");


const selectedRank = interaction.options.get("rank");
const selectedRoleId = selectedRank.value.roleId;

if (!interaction.member.roles.cache.has(selectedRoleId)) {
await interaction.reply("You do not have permission to select that rank!");
return;
}
expected to only be able to select the role if you have the roleid tied to the rank - but the message 'You do not have permission to select that rank!' occurs despite having the correct role to select the rank. No errors
8 replies