Discord.js v14 Button Emoji Error When Putting Emoji ID - discord.js

I included Emoji For Button In My Code IDK The Reason It Crashes Can Someone Say Me The Solution
I Searched Internet And Also Another Stackoverflow Discussion But Didn't Found A Fix
IDK WHAT TO SAY MORE ---------------------------------------------------------------------------------------------------------------------------------------------------------------
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji("<1008747826714521610>")
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1,btn2,btn3)]
})
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await interaction.channel.send('Um Hello');
}
}
});
client.login('SUPER SECRET TOKEN');

You're only supposed to put the emoji ID there, remove the < > and it should work.
.setEmoji("1008747826714521610")
Source: The official discord.js guide

discord emojis put the name of the emoji and the id when sending it to chat like this:
<:emoji_name:0123456789>
This is the format you should use in your code as well otherwise discord has no idea which emoji you want to send.

Have u tried Using the Action Builder With the buttons
I'm from Cody Dimensions The Server u requested help from
Can u try your code like this:
const { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } = ("discord.js")
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const row = new ActionRowBuilder()
.addComponents(
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji("<1008747826714521610>")
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
);
if (message.content === 'hi'){
return message.channel.send({ content: 'HI' components: [row]}))
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await interaction.channel.send('Um Hello');
}
}
});
client.login('SUPER SECRET TOKEN');

I Found Something To Fix This!
If You Are Using Default Emoji Use Unicode Emoji Like This 😊
If You Wanna Use A Custom Emoji You Have To Include :hi:123456789 Like This It Worked For Me
Also Remember To Not To Put The <>
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle, ActivityType } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setPresence({ activity: { name: 'with discord.js' }, status: 'idle' })
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji(':hi:1010402480074539109')
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1,btn2,btn3)]
})
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
interaction.followUp({ content: 'Um Hello', ephemeral: true });
}
}
});
client.login('SUPER SECRET TOKEN');

Related

Embed stated not being sent to channel

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
});
const { EmbedBuilder } = require('discord.js');
// All partials are loaded automatically
//const Discord = require('discord.js');
client.on('ready', async () => {
console.log(`${client.user.username} is ready!`);
})
client.on('guildCreate', (g) => {
const channel = g.channels.cache.find(channel => channel.type === 'GUILD_TEXT' && channel.permissionsFor(g.me).has('SEND_MESSAGES'))
channel.send("Thanks for inviting flappy dank! Please run the command !run to get started!");
})
client.on("messageCreate", async (message) => {
if (message.content == '!testcmd') {
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla)
}
})
I have tried the code above, when I run the command ‘!testcmd’, it does not output any embed. i have searched online for solutions, but none working. I expect and embed to be outputted, yet it doesn’t return any errors. Any advice would be appreciated!
You're using discord.js v14. There's a changes about sending Embeds
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla) //The Changes is in here
The comment line should change as:
message.channel.send({embeds: [illla] });
Click here to see more about EmbedBuilder

Discord bot is getting the message content as null

message.content isn't working with any of the commands I made. It doesn't see my message's content. It's only working when I use message.content === ""
My code:
const Discord = require('discord.js');
const { Client, Intents, Collection } = require('discord.js')
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", (message) => {
if(message.content === ""){
message.reply("I am working");
}
});
client.login("..");

discord.js v13 SlashCommandBuilder Reaction Roles

So i need help with the assign roles part - so if someone click on the reaction(emojiID) it should give the user who clicked on it the role(roleID)..
My code below sends the embed in the channel with my title & description and the emoji, but nothing happend if someone clicked on the emoji!
I use SlashCommandBuilder :
const { SlashCommandBuilder } = require('#discordjs/builders');
const fs = require('fs');
const { Client, Intents, MessageEmbed, MessageReaction } = require('discord.js');
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
],
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
module.exports = {
data: new SlashCommandBuilder()
.setName('reaction')
.setDescription('Create reaction messages')
.addChannelOption((option) => {
return option
.setName('channel')
.setDescription('Choose a channel')
.setRequired(true)
})
...
async execute(interaction, client) {
const channelID = interaction.options.getChannel('channel');
const titleID = interaction.options.getString('title');
const descID = interaction.options.getString('desc');
const emojiID = interaction.options.getString('emoji');
const roleID = interaction.options.getRole('role');
let embed = new MessageEmbed()
.setTitle(titleID)
.setDescription(descID)
channelID.send({ embeds: [embed] }).then((sentMessage) => {
sentMessage.react(emojiID);
The code above is the working part - for the roles - I tried something like
async (reaction, user) => {
if(reaction.interaction.partial) await reaction.interaction.fetch();
if(reaction.partial) await reaction.fetch();
if(user.bot) return;
if(!reaction.interaction.guild) return;
if(reaction.interaction.channel.id === channelID) {
if(reaction.emoji.id === emojiID) {
reaction.interaction.guild.members.cache.get(user.id).roles.add(roleID)
}
}
};
but this is not working, please help :)

Why can't I use an interaction collector in a slash command?

const { SlashCommandBuilder } = require("#discordjs/builders");
const {
MessageEmbed,
MessageActionRow,
MessageSelectMenu,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("setup")
.setDescription("Setup the bot to your server!"),
async execute(interaction) {
let array = [];
await interaction.guild.members.cache.forEach(async (user) => {
if (user.user.bot === false || user.user.id === "925077132865052702")
return;
array.push({
label: user.user.username,
description: user.id,
value: user.id,
emoji: "<a:right:926857658500251668>",
});
});
let row;
if (array < 5) {
row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("select")
.setMinValues(1)
.setMaxValues(parseInt(array.length))
.setPlaceholder("Nothing selected.")
.addOptions(array)
);
} else {
row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("select")
.setMinValues(1)
.setMaxValues(5)
.setPlaceholder("Nothing selected.")
.addOptions(array)
);
}
let welcome = new MessageEmbed()
.setTitle("UChecker | Setup")
.setDescription(
"Please select from the dropdown below all the bots you would like to be notified for."
)
.setColor("FUCHSIA");
let message = await interaction.reply({
embeds: [welcome],
components: [row],
ephemeral: true,
});
const filter = i => {
return i.user.id === interaction.user.id;
};
await message.awaitMessageComponent({ filter, componentType: 'SELECT_MENU', time: 60000 })
.then(async interaction => await interaction.editReply(`You selected ${interaction.values.join(', ')}!`))
.catch(err => console.log(`No interactions were collected.`));
},
};
Here is my code. As you can see at the bottom I am using awaitMessageComponent and it says an error:
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
at Object.execute (C:\Users\Owner\Desktop\UChecker\src\setup.js:55:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.<anonymous> (C:\Users\Owner\Desktop\UChecker\index.js:38:3)
C:\Users\Owner\Desktop\UChecker\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
^
Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred.
at CommandInteraction.reply (C:\Users\Owner\Desktop\UChecker\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90:46)
at Client.<anonymous> (C:\Users\Owner\Desktop\UChecker\index.js:41:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
[Symbol(code)]: 'INTERACTION_ALREADY_REPLIED'
}
I am confused as I thought you could edit a reply? Could someone please help me out because I am really confused. I have created a reply so then it can be edited by the interaction collector and it says it has already replied.
You have to use CommandInteraction#fetchReply() to retrieve the reply message.
await interaction.reply({
embeds: [welcome],
components: [row],
ephemeral: true,
});
const message = await interaction.fetchReply();
Interaction replies are not returned unless you specify fetchReply: true in the options
let message = await interaction.reply({
embeds: [welcome],
components: [row],
ephemeral: true,
fetchReply: true
})

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'text' of null

I'm making a starboard with discord.js. I keep getting this error ("UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'text' of null") whenever I add the star reaction to my message, and I'm not sure why. I tried changing the channel and it works, but whenever I try to set it up in the channel - ﹗﹗starboard it sends the error message. I also made sure my bot had all the permissions it needed to send messages in the channel. Here is my code:
const { Client, MessageEmbed } = require('discord.js');
const client = new Client({ partials: ['MESSAGE', 'REACTION']});
const { token } = require('./config.json');
client.login(token)
const activities_list = [
"Starboard",
"Music",
"Stars",
];
client.on('ready', () => {
console.log(`${client.user.tag} has logged in.`);
});
client.once('ready', () => {
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
client.user.setActivity(activities_list[index], {
type: "LISTENING",
});
}, 10000);
client.user.setStatus('dnd');
console.log(`${client.user.tag}'s status / activity was set.`)
})
client.on('messageReactionAdd', async (reaction, user) => {
const handleStarboard = async () => {
if (!reaction.message.content) reaction.message.content = '・image (click **link**)'
let embed2 = new MessageEmbed()
.setColor('#2f3136')
.setTitle(`Starboard!`)
.setAuthor(reaction.message.author.tag, reaction.message.author.displayAvatarURL())
.setDescription(`> \`⭐\`・${reaction.count}`)
.addField('> Message', reaction.message.content)
.addField('> Message __Info__', `・channel: ${reaction.message.channel}\n・link: [click here](${reaction.message.url})`)
.setFooter(reaction.message.id)
.setTimestamp()
const starboard = client.channels.cache.find(c => c.name === '﹗﹗starboard');
const msgs = await starboard.messages.fetch({ limit: 100 });
const existingMsg = msgs.find(msg =>
msg.embeds.length === 1 ?
(msg.embeds[0].footer.text.startsWith(reaction.message.id) ? true : false) : false);
if(existingMsg) existingMsg.edit(embed2);
else {
const embed = new MessageEmbed()
.setColor('#2f3136')
.setTitle(`Starboard!`)
.setAuthor(reaction.message.author.tag, reaction.message.author.displayAvatarURL())
.setDescription('> \`⭐\`・1')
.addField('> Message', reaction.message.content)
.addField('> Message __Info__', `・channel: ${reaction.message.channel}\n・link: [click here](${reaction.message.url})`)
.setFooter(reaction.message.id)
.setTimestamp()
if(starboard)
starboard.send(embed);
}
}
if(reaction.emoji.name === '⭐') {
if(reaction.message.channel.name === '﹗﹗starboard') return;
if(reaction.message.partial) {
await reaction.fetch();
await reaction.message.fetch();
handleStarboard();
}
else
handleStarboard();
}
});
client.on('messageReactionRemove', async (reaction, user) => {
const handleStarboard = async () => {
if (!reaction.message.content) reaction.message.content = '・・image (click **link**) (click **link**)'
let embed3 = new MessageEmbed()
.setColor('#2f3136')
.setTitle(`Starboard!`)
.setAuthor(reaction.message.author.tag, reaction.message.author.displayAvatarURL())
.setDescription(`> \`⭐\`・${reaction.count}`)
.addField('> Message', reaction.message.content)
.addField('> Message __Info__', `・channel: ${reaction.message.channel}\n・link: [click here](${reaction.message.url})`)
.setFooter(reaction.message.id)
.setTimestamp()
const starboard = client.channels.cache.find(c => c.name === '﹗﹗starboard');
const msgs = await starboard.messages.fetch({ limit: 100 });
const existingMsg = msgs.find(msg =>
msg.embeds.length === 1 ?
(msg.embeds[0].footer.text.startsWith(reaction.message.id) ? true : false) : false);
if(existingMsg) {
if(reaction.count === 0)
existingMsg.delete({ timeout: 2500 });
else
existingMsg.edit(embed3)
};
}
if(reaction.emoji.name === '⭐') {
if(reaction.message.channel.name === '﹗﹗starboard') return;
if(reaction.message.partial) {
await reaction.fetch();
await reaction.message.fetch();
handleStarboard();
}
else
handleStarboard();
}
});

Resources