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
Related
This is the code i used:
bot.on("message", function (message) {
if (message.content == '.shift') {
const channel01 = bot.channels.cache.find(channel => channel.id === "ChannelIDhere")
channel01.send('Text');
}
});
However it doesn't work for me, Most likely it is Outdated, after all the reference i found is a year ago, or i simply made a mistake.
Edit:
client.on('msg', msg => {
if (msg.content === '.go') {
const channel01 = client.channels.cache.get("872654795364765756");
channel01.send('Text');
}
});
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 have a little question.
I'm currently in the progress of trying out creating a tickets bot, and had the idea of having so when a user types !close, it would present him with an embed, asking him if he really does want to close it using reactions (:wastebasket: for Yes, :x: for No).
If the user reacts for Yes, the channel will close. As for No, the embed message will be deleted.
I will be glad to help.
You can use something a little like this:
const prevMsg = message
message.channel.send(embed).then(message => {
const questionMessage = message;
questionMessage.react('🗑️')
.then(() => questionMessage.react('❌'));
const filter = (reaction, user) => {
return ['🗑️', '❌'].includes(reaction.emoji.name) && user.id === prevMsg.author.id;
};
questionMessage.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '🗑️') {
// closing function here
} else {
questionMessage.delete();
}
})
})
If it didn't work, please let me know!
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('AC0');
client.user.setActivity('Tornaments', { type: 'WATCHING'}).catch(console.error);
});
const tornament = new Discord.MessageEmbed()
.setColor('#000ff')
.setTitle('AC0 Tornaments')
.setDescription(`1. TORNAMENT1
2. TORNAMENT2
3. TORNAMENT3
4. TORNAMENT4`)
client.on('message', message => {
if (message.author.id === '694644198531661844') {
if (message.content === '>endac0') {
process.exit();
}}
if (message.content === '>tornaments') {
message.channel.send(tornament);
}
if (message.content.startsWith('>tornamentsadd')){
client.users.fetch('694644198531661844').then(user => {
user.send(`${message.content.toString()}`)
});}
});
client.login('')
How would I make it not spam me I don't think there is a loop or anything in it also I don't know what else to add so yeah I will just keep typing
You just have to add a return function at the end.
if (message.content.startsWith('>tornamentsadd')){
client.users.fetch('694644198531661844').then(user => {
return user.send(`${message.content.toString()}`)
I'm trying to make it so when my bot picks up a reaction in a specific channel, it'll see if it hit 10 reactions on a specific reaction. Then it'll delete the reacted message and post it into another specific channel with a message attached to it.
Here's the code
doopliss.on('message', message => {
if (message.channel.id === "587066921422290953") {
setTimeout(function(){
message.react(message.guild.emojis.get('587070377696690177'))
}, 10)
setTimeout(function(){
message.react(message.guild.emojis.get('587071853609353256'))
}, 50)
setTimeout(function(){
message.react(message.guild.emojis.get('587070377704816640'))
}, 100)
}
});
const message = require("discord.js");
const emoji = require("discord.js");
const reaction = require("discord.js");
doopliss.on('message', message => {
if (message.channel.id === "587066921422290953") {
let limit = 2; // number of thumbsdown reactions you need
if (message.reaction.emoji.name == message.guild.emojis.get('587070377696690177')
&& reaction.count >= limit) message.reaction.message.delete();
let tcontent = message.reaction.message.content
let accept = message.guild.channels.get('587097086256873483')
accept.send(`${tcontent} \`\`\`This server suggestion has been accepted by the community! Great job! Now a staff member just needs to forward it to username.\`\`\``)
}})
Can't figure out how to do this.
Expected Result: Bot sees if post has 10 reactions, then delete it and take the same message to a different channel
Actual Result: An error occurs Cannot read 'channel' property
First I want to say that some question here like this one have what you search.
Moreover, the discord documentation and the guide provide an awaiting reactions section.
There is some other question that refer to the subject or the function used in the guide and by searching a bit you can even find question like this one which is almost the same thing as you.
However, here is a complete example of what you want to do. You can add a timer to the promise instead of just waiting. I didn't use the reaction collector because promise are a bit faster, but you can also create a management system of multiple collector , or use the client.on('messageReactionAdd').
const Discord = require('discord.js');
const config = require('./config.json');
const channelSuggestion = '<channelID>';
const channelSend = '<channelID>';
const emojiReact = '<emojiID>';
const prefixSuggestion = '!';
const reactionMax = 11;
const client = new Discord.Client();
client.on('ready', () => {
console.log('Starting!');
client.user.setActivity(config.activity);
});
client.on('message', (msg) => {
if ((msg.content[0] === prefixSuggestion) && (msg.channel.type === 'dm')){
sendSuggestion(msg);
}
});
function filter(reaction) {
return reaction.emoji.id === emojiReact;
}
function moveSuggestion(msg) {
client.channels.get(channelSend).send(msg.content)
.then(() => msg.delete()).catch(err => console.log(error));
}
function sendSuggestion(msg){
client.channels.get(channelSuggestion).send(msg.content.substr(1))
.then((newMsg) => newMsg.react(emojiReact))
.then((newMsgReaction) =>
newMsgReaction.message
.awaitReactions(filter, {max: reactionMax})//, time: 15000, errors: ['time']})
.then(collected => {
moveSuggestion(newMsgReaction.message);
})
// .catch(collected => {
// console.log(`After a minute, only ${collected.size} out of 10 reacted.`);
// })
);
}
client.login(config.token)
.then(() => console.log("We're in!"))
.catch((err) => console.log(err));
The bot will listen to dm message (I don't know how you want your bot to send the suggestion message, so I made my own way) which start with a !.
Then the bot will send a message to a specific channel, wait for N person to add a reaction, and then will send the message to another channel.