So, I've managed to make my reaction collector work. However, it doesn't actually do anything when I react on a reaction. I added a console.log function inside of my collector.on section, which DOES work, but the switch in it does not. Here's the code.
console.log(`User Report Created (reportCreated = true)`);
try {
await newUserEmbed.react("🔨");
await newUserEmbed.react("❌");
await newUserEmbed.react("❓");
} catch (err) {
message.channel.send('`ERROR: Reactions Error`');
throw err;
};
const collector = newUserEmbed.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("MANAGE_CHANNELS"),
{ dispose: true }
);
collector.on('collect', (message, reaction, user) => {
console.log('Collecting Reactions for User Report (collectorRun = true)');
switch (reaction.emoji){
case "🔨":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been marked as completed.`);
break;
case "❌":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been declined.`);
break;
case "❓":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been marked as inconclusive.`);
break;
}
});
change reaction.emoji to reaction.emoji.name ?
if it does not working
plz type it console.log(reaction.emoji)
and tell me the result.
There is no 'message' parameter in collect event. See: discord.js Documentation
collector.on('collect', (reaction, user) => {
console.log('Collecting Reactions for User Report (collectorRun = true)');
switch (reaction.emoji){
case "🔨":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been marked as completed.`);
break;
case "❌":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been declined.`);
break;
case "❓":
newUserEmbed.delete();
message.reply(`This report for ${args[1]} has been marked as inconclusive.`);
break;
default:
break;
}
});
Related
I'm trying to do bot in js that when users do the command: !mugg #someone //someone is another user mention.
it will say: The Mugger is approaching ${user}, and then after 10 seconds if the user that got mugged won't type !killmugger he will get the message The Mugger mugged ${user} but if he does he will get the message: The mugger didn't mug ${user}.
This is what i tried to do: (I tried to play with if and roles)
bot.on("message", (message) => {
let args = message.content.substring(PREFIX.length).split(" ");
bot.user.setActivity("!mugg #someone");
switch (args[0]) {
case "mug":
const user = message.mentions.members.first();
let Role = message.guild.roles.cache.get("772195872133742634");
if (user) {
const member = message.guild.member(user);
if (member) {
message.reply(`The Mugger is approaching ${user}`);
user.roles.add("Role");
} else {
message.reply("That user isn't in this server.");
}
} else {
message.reply("You need to mention a user");
}
setTimeout(function () {
if (!message.mentions.roles.has("772195872133742634")) {
message.channel.send(`The Mugger mugged ${user}`);
user.roles.remove(Role);
}
}, 10000);
break;
case "killmugger":
const user1 = message.mentions.members.first();
let Role1 = message.guild.roles.cache.get("772195872133742634");
if (!message.mentions.roles.has("772195872133742634")) {
message.channel.send(`The Mugger not mugged ${user1}`);
user1.roles.remove(Role1);
}
}
});
Welcome,
Like #Saddy mentioned you can use awaitMessages, in the following way you don't need to verify if the user has the needed roles.
message.channel.send(`The Mugger mugged ${user}`);
//filter where m is message and the author needs to be the user you mentioned and the content needs to be equal to killmugger or you can change it to !killmugger
const filter = m => m.author.id == user!.id && m.content.toLowerCase() == "killmugger"
//awaitMessage function max: maximum messages, time: in milliseconds and the errors in this case we just need time to make sure that after
//10s it will return the message if he doesn't write killmuger in time
message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] }).then(m => {
return console.log("He got it in time")
}).catch(() => {
return message.channel.send(`The Mugger not mugged ${user1}`);
})
I am attempting to make a report command for my bot, but I seem to get no response whatsoever
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(' ');
switch(args[0]){
case 'report':
message.delete(3000);
let target = message.mentions.members.first() || message.guild.members.get(args[0]);
if(!target) return message.channel.send('Please provide a user that you wish to report').then(m => m.delete(15000));
let reason = args.slice(1).join(" ");
if(!reason) return message.channel.send(`Please provide a reason for reporting **${target.user.username}**`).then(m => m.delete(15000));
let reportChannel = message.guild.channels.cache.find(x => x.name === "📒▸logs");
message.channel.send('Your report has been filed to the staff team. Thank you for reporting!').then(m => m.delete(15000));
reportChannel.send(`**${message.author.username}** has reported **${target.user.username}** for **${reason}**.`);
break;
};
});
Assuming you are using discord.js v12, I've made some edits to make this code works.
First, the new discord.js Message#delete() method requires now a parameter:
So change:
• message.delete(3000); -> message.delete({timeout: 3000});
• message.guild.members.get() -> message.guild.members.cache.get()
• Also, it's args.slice(2) instead of args.slice(1) to properly remove the user mention too.
Here is the final result ^
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(' ');
switch(args[0]){
case 'report':
message.delete({timeout: 3000});
let target = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
if(!target) return message.channel.send('Please provide a user that you wish to report').then(m => m.delete({timeout: 15000}));
let reason = args.slice(2).join(" ");
if(!reason) return message.channel.send(`Please provide a reason for reporting **${target.user.username}**`).then(m => m.delete({timeout: 15000}));
let reportChannel = message.guild.channels.cache.find(x => x.name === "📒▸logs");
message.channel.send('Your report has been filed to the staff team. Thank you for reporting!').then(m => m.delete({timeout: 15000}));
reportChannel.send(`**${message.author.username}** has reported **${target.user.username}** for **${reason}**.`);
break;
};
});
switch(args[0]){
case 'ping':
message.reply('pong!');
break;
case 'play':
if (message.member.voice.channel) {
if(args[1]){
const connection = message.member.voice.channel.join();
const dispatcher = connection.playStream(ytdl(args[1]));
}else{
message.reply('Tio, el link joder');
}
} else {
message.reply('Pero tio, únete al canal de voz');
}
break;
case 'info':
message.reply('No soy el FBI,hippie');
break;
case 'clear':
if(!args[1]) return message.reply('Hippie,que te falta un argumento')
message.channel.bulkDelete(args[1]);
break;
}
});
I tried to seek in other questions the solutions but none of this are what i need or doesnt work,here is the error TypeError: connection.playStream is not a function
In the new v12 update, playStream has been defunct.
the new proper code is
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));
instead of playStream it is just play.
ive been troubleshooting the same code your running, here is the full play,stop and skip commands. I cant figure out the queue though but this should fix your errors with it not running.
case 'play':
if(usedCommandRecently4.has(message.author.id)){
message.reply("Your using this command to fast!");
} else{
function play(connection, message){
var server = servers[message.guild.id];
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
message.channel.send("``Music Bot v1.2`` \n Adding song to queue!");
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
})
}
if(!args[1]){
message.channel.send("``Music Bot v1.2`` \n you need to provide a link!!");
return;
}
if(!message.member.voice.channel){
message.channel.send("``Music Bot v1.2`` \n You must be in a voice channel to play music!");
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voiceConnection)message.member.voice.channel.join().then(function(connection){
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));
play(connection, message);
})
usedCommandRecently4.add(message.author.id);
setTimeout(() => {
usedCommandRecently4.delete(message.author.id)
}, 10000);
}
break;
case 'skip':
if(usedCommandRecently3.has(message.author.id)){
message.reply("Your using this command to fast!");
} else{
var server = servers[message.guild.id];
if(server.dispatcher) server.dispatcher.end();
message.channel.send("``Music Bot v1.2`` \n Skipping the current song!")
usedCommandRecently3.add(message.author.id);
setTimeout(() => {
usedCommandRecently3.delete(message.author.id)
}, 3000);
}
break;
case 'stop':
var server = servers[message.guild.id];
if(message.guild.voice.connection){
for(var i = server.queue.length -1; i >=0; i--){
server.queue.splice(i, 1);
}
server.dispatcher.end();
message.channel.send("``Music Bot v1.2`` \n Ending the queue and Leaving the voice channel! \n This bot is in early development! \n if you have any problems with it dm Justice#6770!")
console.log('stopped the queue')
}
}
if(message.guild.connection) message.guild.voiceConnection.disconnect();
I have tried to make a simple discord bot with the command (!clear) with permissions. I want the "Admin perms" role to be the only role allowed to do the !clear command. Every time I try to do the command its says that message.guild.roles.find is not a function. The code I have right now is:
switch(args[0]){
case 'clear':
if(message.guild.roles.find(role => role.name === 'Admin perms')) {
if(!args[1]) {
return channel.reply ('How many message do you want me to delete idot!')
}
message.channel.bulkDelete(args[1]);
if(!message.member.roles.cache.find(r => r.name === "Admin perms")) return message.channel.send('You dont have permissions to do that idot!')
if(!args[1]) return message.reply('How many message do you want me to delete idot!')
message.channel.bulkDelete(args[1]);
break;
Try Doing this:
switch(args[0]) {
case 'clear':
if (message.member.roles.cache.find(role => role.name === 'Admin perms')) {
if(!args[1]) {
return channel.reply ('How many message do you want me to delete idot!')
}
else {
message.channel.bulkDelete(args[1]);
}
}
break;
I'm trying to iterate through an enmap for my discord.js bot, I've managed to set and get values from a single entry but I'm trying to set up a command that adds people to a newsletter like DM about minor major updates.
if (args[0] === 'minor') {
if (devlog.updates === 'minor') return message.channel.send('You are already recieving minor updates.').then(m => m.delete(5000))
await client.devlog.set(userID, "yes", 'subscribed');
await client.devlog.set(userID, "minor", 'updates');
return message.channel.send('You will now recieve minor and major updates.').then(m => m.delete(5000))
}
if (args[0] === 'major') {
if (devlog.updates === 'major') return message.channel.send('You are already recieving major updates.').then(m => m.delete(5000))
await client.devlog.set(userID, "yes", 'subscribed');
await client.devlog.set(userID, "major", 'updates');
return message.channel.send('You will now recieve only major updates.').then(m => m.delete(5000))
}
if (!args[0]) {
if (devlog.subscribed === 'yes') {
await client.devlog.set(userID, "no", 'subscribed');
await client.devlog.set(userID, "none", 'updates');
return message.channel.send('You will stop recieving updates about RoboTurtle all together').then(m => m.delete(5000))
}
if (devlog.subscribed === 'no') {
return message.channel.send(`Please choose wether you\'d like to recieve minor or major updates! (minor has both) **devlog minor/major**`).then(m => m.delete(10000))
}
}
It kind of works but it won't trigger the message if they already are subscribed to the same type of update and if they do just !devlog it's meant to either set them to not receive updates if they already are, or tell them to choose between the two if they aren't, however it just sends the last message either way.
I tried setting up my enmap iteration for DMing all subscribed people with a for...of function based off the .map related docs (since they're meant to be just "fancier" maps) but to no avail, since they don't really show discord style use cases.
if (args[0] === 'minor') {
for (let entry of client.devlog) {
if (entry.updates === 'minor') {
let user = client.users.get(entry)
user.send(`**[Minor Update]\n${args.slice(1)}`)
}
}
}
if (args[0] === 'major') {
for (let entry of client.devlog) {
if (entry.subscribed === 'yes') {
let user = client.users.get(entry)
user.send(`**[Major Update!]\n${args.slice(1)}`)
}
}
}
In case anyone wanted to look at the full code to get a better idea of what Im trying to do here ya go: https://pastebin.com/bCML6EQ5
Since they are just an extension of the normal Map class, I would iterate through them with Map.forEach():
let yourEnmap = new Enmap();
yourEnmap.set('user_id', 'your_values');
yourEnmap.forEach((value, key, map) => {
...
});
In your case it would be something like:
client.devlog.forEach((values, user_id) => {
// you can check your subscription here, the use the user_id to send the DM
client.users.get(user_id).send("Your message.");
});