I was using something like this but i want it to look for reactions in the embed sent! not in the message
const collector = message.createReactionCollector((reaction, user) =>
user.id === message.author.id &&
reaction.emoji.name === "◀" ||
reaction.emoji.name === "▶" ||
reaction.emoji.name === "❌"
).once("collect", reaction => {
const chosen = reaction.emoji.name;
if(chosen === "◀"){
// Prev page
}else if(chosen === "▶"){
// Next page
}else{
// Stop navigating pages
}
collector.stop();
});
A RichEmbed is sent as part of a message. Therefore, when you add a reaction, it's on the message, not the embed.
See the example below which gives the appearance of reactions on an embed.
const { RichEmbed } = require('discord.js');
var embed = new RichEmbed()
.setTitle('**Test**')
.setDescription('React with the emojis.');
message.channel.send(embed)
.then(async msg => {
// Establish reaction collector
for (emoji of ['◀', '▶', '❌']) await msg.react(emoji);
})
.catch(console.error);
Related
I have a suggest command on my bot that im working on. However it only works when the user suggesting is in my server since it is codded to send the suggestion to a specific channel id. Is there a way to code it where the suggestion comes to my dms or specified channel even if the user suggesting isn't in the server? here is my code:
const { MessageEmbed } = require("discord.js")
module.exports.run = async (client, message, args) => {
if (!args.length) {
return message.channel.send("Please Give the Suggestion")
}
let channel = message.guild.channels.cache.find((x) => (x.name === "sauce-supplier-suggestions" || x.name === "sauce-supplier-suggestions"))
if (!channel) {
return message.channel.send("there is no channel with name - sauce-supplier-suggestions")
}
let embed = new MessageEmbed()
.setAuthor("SUGGESTION: " + message.author.tag, message.author.avatarURL())
.setThumbnail(message.author.avatarURL())
.setColor("#ff2050")
.setDescription(args.join(" "))
.setTimestamp()
channel.send(embed).then(m => {
m.react("✅")
m.react("❌")
})
message.channel.send("sucsessfully sent your suggestion to bot team thank you for your suggestion!!")
}
I made some small changes in your code. Now if a user uses the command correctly, the bot will send you a DM with the users suggestion.
const { MessageEmbed } = require("discord.js")
module.exports.run = async (client, message, args) => {
let suggestion = args.join(" ");
let owner = client.users.cache.get("YOUR ID");
if (!suggestion) {
return message.channel.send("Please Give the Suggestion")
}
let channel = message.guild.channels.cache.find((x) => (x.name === "sauce-supplier-suggestions" || x.name === "sauce-supplier-suggestions"))
if (!channel) {
return message.channel.send("there is no channel with name - sauce-supplier-suggestions")
}
let embed = new MessageEmbed()
.setAuthor("SUGGESTION: " + message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
.setThumbnail(message.author.displayAvatarURL({ dynamic: true }))
.setColor("#ff2050")
.setDescription(suggestion)
.setTimestamp()
owner.send(embed).then(m => {
m.react("✅")
m.react("❌")
})
message.channel.send("sucsessfully sent your suggestion to bot team thank you for your suggestion!!")
}
I am trying to create a message with reactions for my bot, if a user clicks on a specific reaction he is automatically given a role chosen by me via code. I don't understand where the problem is in what I've done.
await msg.react('🤜');
if (reaction.emoji.name === '🤛') {
if (reaction.message.channel.id === "793239655331004448");
let role = reaction.guild.roles.cache.find(role => role.id === '689880327782400203');
member.roles.add(role.id);
console.log('Ruolo Aggiunto'); //role added
} else {
console.log("Errore"); //Error
}```
await msg.react('🤜');
if (reaction.emoji.name === '🤛') {
if (reaction.message.channel.id === "793239655331004448");
console.log('lol');
let role = reaction.guild.roles.cache.find(role => role.id === '689880327782400203');
console.log('lol');
member.roles.add(role);
console.log('Ruolo Aggiunto'); //role added
} else {
console.log("Errore"); //Error
}```
I been trying to make my bot reply to users when they react to the bots emoji but no luck I hope someone can help me here, I'm just a beginner with discord.js.
here's my code I just need help with the part where the bot sends a message back once the user reacts to it.
bot.on('message', message => {
if(message.author.bot)
{
if(message.embeds)
{
const embedMsg = message.embeds.find(msg => msg.title === 'Next step');
if(embedMsg)
{
message.react('708923041928839169')
.then(reaction => reaction.message.react('708923028846805073'))
.catch(err => console.error);
}
}
return;
}
if(message.content.toLowerCase() === 'done'){
const embed = new Discord.MessageEmbed();
embed.setTitle('Next step')
embed.setColor(colors.blue);
embed.setDescription('Please react to Agree or Disagree');
message.channel.send(embed)
}
});
bot.login(token);
You can simply use a ReactionCollector to do this. The documentation for this can be found easily on the discord.js docs, and I would recommend you look there when unsure of how to do something before asking a question on StackOverflow.
Here's an example using your code:
bot.on('message', message => {
if(message.author.bot) return;
if(message.content.toLowerCase() === 'done'){
const embed = new Discord.MessageEmbed();
embed.setTitle('Next step')
embed.setColor(colors.blue);
embed.setDescription('Please react to Agree or Disagree');
message.channel.send(embed).then(embedMsg => {
embedMsg.react('708923041928839169')
.then(reaction => embedMsg.react('708923028846805073'))
.catch(err => console.error);
const filter = (r, u) => r.emoji.id == '708923041928839169' || r.emoji.id == "708923028846805073";
const collector = message.createReactionCollector(filter, {time: 60000});
collector.on('collect', (r, u) => {
//Put your response to reactions here
message.channel.send("Reply with something to " + u.tag + " because they reacted with " + r.emoji.name);
});
})
}
});
bot.login(token);
I also moved your code in which you add the reactions to the Embed, because the way you were doing it was an unnecessary extra step.
Relevant resources:
https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=createReactionCollector
i would like to create a reaction role function to my bot (there IS a message, then if any member reacts to the message, he gets a role. Like in MEE6).
I've tried this...
client.on('messageReactionAdd', (messageReaction, user) => { if(user.bot) return; const { message, emoji } = messageReaction; if(emoji.name === "✅") { if(message.id === "713071578174193745") {
var role = message.guild.roles.find(role => role.name === "Nem hitelesített 2")
user.addRole(role)
var role = message.guild.roles.find(role => role.name === "Nem hitelesített 1")
user.removeRole(role)
}}},)
client.on("messageReactionAdd", (reaction, user) => {
console.log("1");
if (reaction.message.channel.id !== "713066051969220631" && reaction.emoji.name !== '✅') {
return;
}
client.guilds.get(yourguildid).member(user).addRole('713065834771120172')
}
but i didn't reach anything. Can you help me please?
Note: I'm on v11. By another man, it worked, he was on v11 too. The ÍTRIGGER isn't working, if i put console.log before if, and i'm reacting, no answer.
I want the bot to change member permissions and set "send messages" to false if someone uses $done #user.
client.on('message', async message => {
if (message.author.bot) return;
if (message.content === prefix + "done") {
var user = message.guild.member(message.mentions.users.first());
message.channel.overwritePermissions(user, {
SEND_MESSAGES: false
});
}
});
You should either use:
const user = message.mentions.users.first();
or
const user = message.mentions.members.first();
and then add a
if(!user) return messsage.channel.send('You need to mention a user!'); below the `const user` line.