someone can help?
5️⃣ = 5️⃣
var embed1 = new Discord.RichEmbed()
.setTitle("hjgsadgv")
message.channel.send(embed9)
.then(function (message) {
message.react("5️⃣")
.then(() => message.react("4️⃣"))
.then(() => message.react("3️⃣"))
.then(() => message.react("2️⃣"))
.then(() => message.react("1️⃣"))
const filter = (reaction, user) => {
return ['5️⃣', '4️⃣', '3️⃣', '2️⃣', '1️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;
}
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '5️⃣') {
message.reply('123');
}
else {
message.reply('321');
}
var embed2 = new Discord.RichEmbed()
.setTitle("uysygadk")
message.channel.send(embed10)
})
})
Bot responds to its own reactions
You can ignore bots by changing your filter to this:
const filter = (reaction, user) => {
return ['5️⃣', '4️⃣', '3️⃣', '2️⃣', '1️⃣'].includes(reaction.emoji.name) && user.id === message.author.id && !user.bot;
}
It basically checks the bot property of user and if it's true then the filter blocks it.
Related
I'm trying to have a bot react when users click the emojis on the bot's embeds.
I'm receiving in the console:
UnhandledPromiseRejectionWarning: TypeError: chestEmbed.awaitReactions
is not a function
The code:
module.exports = {
name: 'enterhouse',
aliases: 'eh',
permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
description: "Pick a number",
async execute(client, message, args, Discord){
const chestEmbed = new MessageEmbed()
.setColor('#FFA500')
.setImage('https://imageURL.jpg');
message.channel.send(chestEmbed).then(chestEmbed => {chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣').then(() => chestEmbed.react('3️⃣')))}
)
.catch(() => console.error('One of the emojis failed to react.'));
const filter = (reaction, user) => {
return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
};
chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '1️⃣') {
chestEmbed.delete();
message.reply('you reacted with 1');
} else if (reaction.emoji.name === '2️⃣') {
message.reply('you reacted with 2');
} else {
message.reply('you reacted with 3');
}
})
.catch(collected => {
message.reply('Time is up, you did not react.');
});
}
}
It worked fine when it was message.awaitReactions instead.
Any help is really appreciated!
You are awaiting messages from the embed it's self not the message the embed is in.
Simple fix:
...
chestEmbed = await message.channel.send(chestEmbed)
...
Full Code:
module.exports = {
name: 'enterhouse',
aliases: 'eh',
permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
description: "Pick a number",
async execute(client, message, args, Discord) {
const chestEmbed = new MessageEmbed()
.setColor('#FFA500')
.setImage('https://imageURL.jpg');
chestEmbed = await message.channel.send(chestEmbed)
chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣')).then(() => chestEmbed.react('3️⃣'))
const filter = (reaction, user) => {
return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
};
chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '1️⃣') {
chestEmbed.delete();
message.reply('you reacted with 1');
} else if (reaction.emoji.name === '2️⃣') {
message.reply('you reacted with 2');
} else {
message.reply('you reacted with 3');
}
})
.catch(collected => {
message.reply('Time is up, you did not react.');
});
}
}
so i'm trying to make pagination of embeds (pages) and I'm having a problem.
TypeError: Cannot read property 'channel' of undefined
I'm kinda still new at Discord.js, any help would be apresuated
client.on('message', async (client, message, args, tools) => {
let pages = ['page one', 'second', 'third', 'you can add pages', 'all you need to do is add another item in the array', '**Supports markdown and regular chat description properties**'];
let page = 1;
const embed = new Discord.MessageEmbed()
.setColor('red')
.setFooter(`Page ${page} of ${pages.length}`)
.setDescription(pages[page-1])
message.channel.send(embed).then(msg => {
msg.react('⏮️').then(r => {
msg.react('⏭️')
const backwardsFilter = (reaction, user) => reaction.emoji.name === '⏮️' && user.id === message.author.id;
const forwardsFilter = (reaction, user) => reaction.emoji.name === '⏭️' && user.id === message.author.id;
const backwards = msg.createReactionCollector(backwardsFilter, { time: 60000 });
const forwards = msg.createReactionCollector(forwardsFilter, { time: 60000 });
backwards.on('collect', r => {
if (page ===1) return;
page--;
embed.setDescription(pages[page-1]);
embed.setFooter(`Page ${page} of ${pages.length}`)
msg.edit(embed)
})
forwards.on('collect', r => {
if (page === pages.length) return;
page++;
embed.setDescription(pages[page-1]);
embed.setFooter(`Page ${page} of ${pages.length}`);
msg.edit(embed)
})
})
})
})
My problem is I want to delete d_msg after the reaction of the user. But it forgets what d_msg is and can't delete it. How can I fix it?
function English(thechannel, message) {
client.channels.cache.get(thechannel).send("Do u speak English?").then(d_msg => {
d_msg.react("✅");
d_msg.react("❌");
client.on('messageReactionAdd', async (reaction, user) => {
if (user.tag === theuser) {
if (reaction.emoji.name === '✅') {
var role = message.guild.roles.cache.find(role => role.name === "English");
message.member.roles.add(role);
}
}
d_msg.delete();
});
});
}
const Filter = (reaction, user) => {return (reaction.emoji.name == "✅" || reaction.emoji.name == "❌") && user.id == message.author.id};
message.reply("Do you speak English? \n\n *This prompt will disappear in 30 seconds.*").then(async messageSent => {
await messageSent.react("✅");
await messageSent.react("❌");
messageSent.awaitReactions(Filter, {max: 1, time: 30000, errors: ["time"]}).then(collected => {
messageSent.reactions.removeAll();
if (collected.first().emoji.name == "✅") {
messageSent.edit("You do speak English!");
} else if (collected.first().emoji.name == "❌") {
messageSent.edit("You do not speak English!");
}
}).catch(e => {
messageSent.edit("This prompt expired.");
messageSent.reactions.removeAll();
});
});
I currently have a Discord bot which reads information of a API that deals with a game server panel.
In this Bot there is tasks that are to start/restart/stop/kill the server. i want to give the option for the end user to react to a embed posted by a bot with a certain reaction to trigger these tasks.
The Command and embed that are posted by the bot are:
The code which currently checks which reaction has been triggered looks like this:
message.channel.send(embed).then(async (sentEmbed) => {
sentEmbed.react("🟩")
sentEmbed.react("🔁")
sentEmbed.react("🟥")
sentEmbed.react("❌")
const filter = (reaction, user) => {
console.log(reaction.emoji.name)
return reaction.emoji.name === '🟩' && user.id === message.author.id;
};
const collector = sentEmbed.createReactionCollector(filter, {time: 20000});
collector.on('collect', (reaction, user) => {
Client.startServer(args[0]).then((response) => {
const start_embed = new Discord.MessageEmbed()
.setTitle(response)
.setColor(settings.embed.color.default)
.setFooter(settings.embed.footer);
message.channel.send(start_embed);
}).catch((error) => {
message.channel.send(client.embederror(error))
});
});
const filter2 = (reaction, user) => {
return reaction.emoji.name === '🔁' && user.id === message.author.id;
};
const collector2 = sentEmbed.createReactionCollector(filter2, {time: 20000});
collector.on('collect', (reaction, user) => {
Client.restartServer(args[0]).then((response) => {
const restart_embed = new Discord.MessageEmbed()
.setTitle(response)
.setColor(settings.embed.color.default)
.setFooter(settings.embed.footer);
message.channel.send(restart_embed);
}).catch((error) => {
message.channel.send(client.embederror(error))
});
});
const filter3 = (reaction, user) => {
return reaction.emoji.name === '🟥' && user.id === message.author.id;
};
const collector3 = sentEmbed.createReactionCollector(filter3, {time: 30000});
collector.on('collect', (reaction, user) => {
console.log(`User Stopped There Server`);
});
const filter4 = (reaction, user) => {
return reaction.emoji.name === '❌' && user.id === message.author.id;
};
const collector4 = sentEmbed.createReactionCollector(filter4, {time: 30000});
collector.on('collect', (reaction, user) => {
console.log(`User Killed There Server`);
});
})
This code works for detecting the reactions onto the message, however when a user reacts with any reaction it runs all of the trigger code, so the bot posts two embeds which i have defined as what the bot should output when a reaction is triggered.
I just want the user to click one reaction, then the bot does something, then the use can click another and the bot does something else.
Thanks in advance
The issue was you used collector.on("collect") 4 times instead of using collector2, collector3 and collector4
It's best not to have variables like that since like it shows you might get confused
Plus you should not have 4 different filters and collectors, especially since you repeat a lot of the code
const validEmojis = ['🟩', '🔁', '🟥', '❌'];
const filter = (reaction, user) => {
return validEmojis.includes(reaction.emoji.name) && user.id === message.author.id;
};
const collector = sentEmbed.createReactionCollector(filter, { time: 20000, maxEmojis: 1 });
collector.on('collect', (reaction, user) => {
const name = reaction.emoji.name;
//you only use it in two cases but I assume you will use it for all later on
const embed = new Discord.MessageEmbed()
.setColor(settings.embed.color.default)
.setFooter(settings.embed.footer);
if (name === '🟩' || name === '🔁') {
const method = name === '🟩' ? "startServer" : "restartServer";
Client[method](args[0])
.then(response => {
embed.setTitle(response);
message.channel.send(start_embed);
}).catch((error) => {
message.channel.send(client.embederror(error))
});
} else if (name === '🟥') {
console.log(`User Stopped There Server`);
} else if (name === '❌') {
console.log(`User Killed There Server`);
}
});
I am unable to collect a DM in discord.js when i try to use discord message collector
i have tried changing "message.channel" to message.author but it won't work
const collector = new discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 30000 });
collector.on('collect', message => {
if (message.content == strng) {
message.channel.send(`Successfully Verified User: <#${message.author.id}>`).then(m => {
m.delete(30000)
message.member.addRole('470615991555063808')
}).catch(err => console.log(err));
}
})
expected: user DMs bot with correct string and it verifies them
actual: user has to put the string in the same channel as the user originally said !verify
The user has to put the string in the same channel because you're collecting messages in said channel with message.channel as the first MessageCollector argument.
Instead, what you could do is open a DMChannel with the user and return it with .then() like so:
message.author.createDM().then(dmchannel => {
const collector = new discord.MessageCollector(dmchannel, m => m.author.id === message.author.id, { time: 30000 });
collector.on('collect', m => {
if (m.content == strng) {
message.channel.send(`Successfully Verified User: <#${message.author.id}>`)
.then(m => {
m.delete(30000)
message.member.addRole('470615991555063808')}).catch(err => console.log(err))}
})
})
i have worked it out...
i used
message.author.createDM().then(c => {
var verified = new discord.RichEmbed()
.setTitle("Verification Started")
.addField("**User**", `${message.author}`, false)
.setFooter("Goriko Bot")
.setColor(0xfffb00)
.setTimestamp();
message.guild.channels.get('470619175547830315').send(verified).catch(err => console.log(err));
console.log("DM Created")
c.send(verifyEmbed)
console.log(`Embed Sent to ${message.author.tag}`)
const filter = m => m.content.includes("~");
const collector = c.createMessageCollector(filter, { time: 30000 })
console.log("Collector Created")
collector.on('collect', m => {
console.log('Reply Collected')
if (m.content === strng) {
console.log('Success')
c.send("Successfully Verified")
if (message.channel.type == "dm") return;
message.member.addRole('470615991555063808').catch(err => console.log(err));
var successEmbed = new discord.RichEmbed()
.setTitle("Verification Successful")
.addField("**User**", `${message.author}`, true)
.addField("**String**", `\`\`${strng}\`\``, true)
.setFooter("Goriko Bot")
.setColor(0x00ff00)
.setTimestamp();
message.guild.channels.get('470619175547830315').send(successEmbed).catch(err => console.log(err));
} else {
var failEmbed = new discord.RichEmbed()
.setTitle("Verification Failed")
.addField("**User:**", `${message.author}`, true)
.addField("**Correct Token:**", `${strng}`, true)
.addField("**Token Given:**", `${m.content}`, true)
.setColor(0xff0000)
.setFooter("Goriko Bot")
.setTimestamp();
message.guild.channels.get('470619175547830315').send(failEmbed).catch(err => console.log(err));
m.reply("Invalid Token! Please Try Again")
}
})
})