I want it when I add emoji as a reaction it sends a private message to who added.
Exemple:
https://youtu.be/tcBhXB4Kmqk
You can use client.on('messageReactionAdd', listener) to listen to the reactions.
Inside the listener function, you can check the message id & then send the message.
Here's a sample:
// let's say that the message ID is stored in my_id
client.on('messageReactionAdd', (reaction, user) => {
// this is to avoid the bot sending messages to everyone that reacts anywhere
if (reaction.message.id == my_id) user.send('Your message.');
});
You can also send different messages depending on which reaction was added: you can use ReactionEmoji.name to check that.
To get the Unicode value of a built-in emoji, type the emoji with a backward slash (E.g.: \:joy: will result in 😂).
if (reaction.message.id == my_id) {
if (reaction.name == '😂') user.send('Ayy lmao!11!!');
else user.send('This is another emoji.');
}
Related
There are a lot of to ban a user in a server, you can do it manually or with another bot. I want my bot to scan a banlist, and if someone will get banned, it will send a message "user (id) has been banned
I started writing smt but now, I had no idea what can I do to check it.
EDIT: It's working now, but it still need to find this user id.
client.on('guildBanAdd', message => {
client.user.cache.find() //idk how to define it
const channel1 = client.channels.cache.find(channel => channel.id === "158751278127895");
channel1.send('12512');
})
You don't have to fetch bans because the guildBanAdd event parses a GuildBan object,which als includes a User object.
client.on('guildBanAdd', ban => {
console.log(ban.user.username); // Username
})
message.channel won't work because there isn't a message object.
If you want to get the executor (moderator) who performed the ban, kick etc.
There is a good guide for this Working with Audit Logs
My current code is
message.channel.send(dungeonEmbed).then(sentEmbed => {
sentEmbed.react("⚔️")
})
this sends the embed, and reacts, but I need to figure out a way to check if the original message sender reacts, and to then replace an embed with another
I'm not sure what you want.
Let's guess you want if the author reacts on his own message
client.on("messageReactionAdd", (reaction, user) => {
if(reaction.message.id == "The message ID" && user.id == reaction.message.author.id){
//The author and the original message has reacted
if(reaction.emoji.name == "🐱"){
//The author has reacted the specified emoji
}
}else{
//Just in case
}
})
Please also check this one too Discord js check reaction user role
I'm trying to make a starboard code with my bot, and everything else is working good. But I'm trying to make it to where the bot ignores reactions from the author of the actual message.
This is my current code:
client.on('messageReactionAdd', (reaction_orig, message, user) => {
if (message.author.id === reaction_orig.users.id) return
manageBoard(reaction_orig)
})
It returns the following error:
if (message.author.id === reaction_orig.users.id) return;
^
TypeError: Cannot read property 'id' of undefined
The problem is that messageReactionAdd takes two parameters; the message reaction as the first one, and the user that applied the emoji as the second one. When you write reaction_orig, message, user, reaction_orig is the reaction (which is correct), but message is the user who reacted as it's the second parameter. The user variable will be undefined.
Another issue is that reaction_orig.users returns a ReactionUserManager that doesn't have an id property. Luckily, the user is already passed down to your callback so you can use its ID.
Also, reaction_orig has a message property, the original message that this reaction refers to so you can get its authors' ID from it.
You can change your code to this to work:
client.on('messageReactionAdd', (reaction_orig, user) => {
if (reaction_orig.message.author.id === user.id) {
// the reaction is coming from the same user who posted the message
return;
}
manageBoard(reaction_orig);
});
However, the code above only works on cached messages, ones posted after the bot is connected. Reacting on older messages won't fire the messageReactionAdd event. If you also want to listen to reactions on old messages you need to enable partial structures for MESSAGE, CHANNEL and REACTION when instantiating your client, like this:
const client = new Discord.Client({
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
You can check if the message is cached by e.g. checking if its author property is not null. If it's null, you can fetch the message. Now, you have both the message author and the user who reacted, so you can compare their IDs:
// make sure it's an async function
client.on('messageReactionAdd', async (reaction_orig, user) => {
// fetch the message if it's not cached
const message = !reaction_orig.message.author
? await reaction_orig.message.fetch()
: reaction_orig.message;
if (message.author.id === user.id) {
// the reaction is coming from the same user who posted the message
return;
}
// the reaction is coming from a different user
manageBoard(reaction_orig);
});
Try doing this :
client.on('messageReactionAdd', (reaction, user) => {
if (!reaction.message.author.id === user.id){
//Do whatever you like with it
console.log(reaction.name)
}
});
Note: The message must be cached. For that you'll need to do this
Client.channels.cache.get("ChannelID").messages.fetch("MessageID");
I'm guessing you're using discord.js v12
I am trying to get my discord bot to send this message only if the user starts typing in the defined channel, and not other text channels. I don't get any errors, the bot just doesn't send a message. What am I doing wrong here? Can typingStart be defined to a specific channel?
const Join2_channel = "972135774921247676"
bot.on("typingStart", (message , channel) => {
if (channel.id === Join2_channel) {
message.send('Type !join');
}
});
The typingStart event takes two parameters; channel (the channel the user started typing in) and user (that started typing), in this order.
In your current code you're checking if the user.id is 972135774921247676 and as that's a channel's snowflake, it won't match. You need to update your callback function:
bot.on("typingStart", (channel, user) => {
if (channel.id === Join2_channel) {
channel.send('Type !join');
}
});
I want to make my discord bot send different messages when anyone types a command in a normal channel or NSFW channels.
I followed the documentation, which I didn't quite get it. I wrote the testing commands below:
client.on('message', message => {
if (command === 'testnsfw') {
if (this.nsfw = Boolean(true.nsfw)) {
return message.channel.send('yes NSFW');
} else return message.channel.send('no NSFW');
}
})
I think it is not working. The bot only responds "no NSFW" on both channels.
You cannot refer to the TextChannel using this in the anonymous function. (Also, this is always undefined in an arrow function) You can access the TextChannel using the Message class, stored in the message variable.
client.on("message", message => {
// Making the sure the author of the message is not a bot.
// Without this line, the code will create an infinite loop of messages, because even if a message is sent by a bot account, the client will emit the message event.
if (message.author.bot) return false;
// message.content is a String, containing the entire content of the message.
// Before checking if it equals to "testnsfw", I would suggest to transform it to lowercase first.
// So "testNSFW", "testnsfw", "TeStNsFw", etc.. will pass the if statement.
if (message.content.toLowerCase() == "testnsfw") {
// You can get the Channel class (which contains the nsfw property) using the Message class.
if (message.channel.nsfw) {
message.channel.send("This channel is NSFW.");
} else {
message.channel.send("This channel is SFW.");
}
}
});
What I encourage you to read:
Message
TextChannel
now you can just do this instead
if(!message.channel.nsfw) return message.channel.send('a message to send to channel')
this is using
discord.js verson 13.6.0