Adding new tag to forum channel

The tag is added, with the name correctly set, but the emoji is missing. Here's my code:
client.on("messageCreate", async (message) => {
if (message.content.startsWith("!addTag")) {
const channelIdToCopy = message.content.split(" ")[1];
const tagName = "Help Needed";
const tagEmoji = "❗";

try {
const forumChannel = await client.channels.fetch(channelIdToCopy);

if (!forumChannel || forumChannel.type !== ChannelType.GuildForum) {
message.channel.send("Invalid or non-forum channel ID provided.");
return;
}

const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: tagEmoji },
];

await forumChannel.edit({ availableTags: updatedTags });
} catch (error) {
console.error("Error adding tag with emoji:", error);
message.channel.send(
"An error occurred while adding the tag with emoji."
);
}
}
});
client.on("messageCreate", async (message) => {
if (message.content.startsWith("!addTag")) {
const channelIdToCopy = message.content.split(" ")[1];
const tagName = "Help Needed";
const tagEmoji = "❗";

try {
const forumChannel = await client.channels.fetch(channelIdToCopy);

if (!forumChannel || forumChannel.type !== ChannelType.GuildForum) {
message.channel.send("Invalid or non-forum channel ID provided.");
return;
}

const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: tagEmoji },
];

await forumChannel.edit({ availableTags: updatedTags });
} catch (error) {
console.error("Error adding tag with emoji:", error);
message.channel.send(
"An error occurred while adding the tag with emoji."
);
}
}
});
13 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
P'titeLouise
P'titeLouiseOP13mo ago
No description
P'titeLouise
P'titeLouiseOP13mo ago
I don't get any error in the console, by the way! Trying to directly put the emoji with the brackets in the 'emoji:' field didn't work.
duck
duck13mo ago
it seems the emoji property expects a GuildForumTagEmoji object and doesn't resolve emoji identifiers for you like some other emoji fields
P'titeLouise
P'titeLouiseOP13mo ago
Then what should I put in the code instead please? I want to use this exact emoji: ❗
duck
duck13mo ago
since this is a unicode emoji, a { name } object
P'titeLouise
P'titeLouiseOP13mo ago
I'm confused, would that work?
const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: { name: exclamation }},
];
const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: { name: exclamation }},
];
duck
duck13mo ago
if exclamation is ❗ , sure
P'titeLouise
P'titeLouiseOP13mo ago
Let me try It is on Discord I think
duck
duck13mo ago
I meant literally if the variable named exclamation has a value of that is the name of the emoji, yes
P'titeLouise
P'titeLouiseOP13mo ago
Yeah, this worked:
const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: { name: "❗" } },
];
const updatedTags = [
...forumChannel.availableTags,
{ name: tagName, emoji: { name: "❗" } },
];
Thank you for your help @duck I'll close the post now
Want results from more Discord servers?
Add your server