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!
Related
I'm making a giveaway command for my server, all from my knowledge without following a tutorial.
I'm running into an issue. I don't know how to use the collector's information to determine if there is enough reactions or not, and to get a winner.
My code:
const filter = (reaction, user) => {
return reaction.emoji.name === '🎉' && user.id === message.author.id;
};
const collector = message.createReactionCollector({ filter, time: duration });
collector.on('collect', (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
setTimeout(() => {
if (collector <= 1) {
message.channel.send("Not enough people reacted for me to draw a winner")
return}
let winner = (m) => m.reaction.cache.get("🎉").users.cache.filter((u) => !u.bot).random();
channel.send(`Congratulations ${winner} You just won the **${prize}**!`
);
}, duration );
Any help please? Thank you!
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');
}
});
After about 20 hours of searching for answers, editing the code, and trying new methods. I've given up and decided to ask here.
I'm absolutely sick of this piece of code.
What I'm trying to do is: 1. Wait for a message to receive 2 reactions 2. After 2 reactions, post message to a separate channel
EDIT: After some users recommended removing my stupidly placed console.log before my .then this code now proceeds to not wait for a reaction on a message and go through the entire process without posting a message to the specified channel
Please bear with me, I'm still learning.
Here's the code:
client.on('message', msg => {
const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === message.author.id;
msg.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
.then(collected => {
const starboard = new Discord.MessageEmbed()
.setColor(0xFF0000)
.setAuthor(`${msg.author.username}`, `${msg.author.avatarURL()}`)
.setDescription(`${msg.author.content}`)
client.channels.cache.get('714842643766444122').send(starboard)})
.catch(err => console.log(err), ('Passed! Added to starboard.'));
console.log('Added to Starboard!');
If you need more details, Please ask.
client.on('message', async msg => {
let rMessage = await msg.channel.send("Test Message");
await rMessage.react('703033480090484756');
const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === msg.author.id;
rMessage.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
.then(collected => {
const starboard = new Discord.MessageEmbed()
.setColor(0xFF0000)
.setAuthor(`${msg.author.username}`, `${msg.author.displayAvatarURL()}`)
//.setDescription(`${msg.author.content}`)
client.channels.cache.get('714842643766444122').send(starboard)})
.catch(err => console.log(err), ('Passed! Added to starboard.'));
console.log('Added to Starboard!');
You used .then on your console.log('Woah! Passed the filter...').
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'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.