I want to use .react() from DM way. But the reaction into the post is sended by bot. I need send a reaction by the user.
var guild = bot.guilds.get(GUILD_ID);
if(guild && guild.channels.get(ch_ID)){
guild.channels.get(ch_ID).fetchMessage(msg_ID).then(message => {
message.react('🤔')
})
}
As I shared in a comment...
A client cannot add a reaction as another user.
Unfortunately, that means that you can't accomplish what you're trying to do within the Discord API. You can read reactions, but the bot simply would never be able to force someone to add a reaction.
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
Wanted to make the bot dm a person who uses the command to get a hint based on the puzzle role they had.
did watch a YT vid that showed to dm a person based on a trigger. That didn't help as it needs too many triggers.
the bot should dm a person on what role they have
so I do know we need to use if (message.member.roles.cache.some(role => role.name === 'Puzzle 1')
Not completely sure on how to make it :'(
You can use message.author.send("YOUR MESSAGE HERE") for sending a private message to the user.
If you want to check user role by name before sending DM, you can make something like that:
if (message.member.roles.cache.some(role => role.name === 'Puzzle 1')){
message.author.send("YOUR MESSAGE HERE")
}
IMPORTANT NOTE: If a user disabled Allow direct messages from server members on privacy & safety settings, the bot can't send a message to a user. So I recommend you to use try/catch.
So I'm trying to make a bot that send a message to all the servers that it is in, but the problem is that I don't really know how to make the user chose the specific channel that he wants, and that I don't know how to make the bot send a message to the servers that the bot is in. If someone could help, or tell me about a tutorial that would be appreciated!
Problem #1: How to make a user chose a channel that that the bot sends the message in.
Problem #2: How to Make the bot send a message to all the servers that he is in.
If you would like to state all servers a bot is in, you can use a forEach method. Like so:
let servernames = "";
bot.guilds.cache.forEach(guild => {
servernames += `${guild.name}, `;
});
message.channel.send(`**${servernames.slice(0, servernames.length - 2)}**`)
However, if you are looking to send a message to every server regardless, you would still need a forEach method, simply join with the .send function. Example:
bot.guilds.cache.forEach(guild => {
guild.defaultChannel.send("hi")
});
If you want to send a message to a specific channel, you need to cache it and find using the channel ID. Example:
let channelSend = bot.channels.cache.find(channel => channel.id === 'channel id here')
channelSend.send("hi")
I am making a discord bot in discord.jsV12 that auto sets up a server. For this to happen i need the bot to delete all channels. I have tried msg.guild.channels.forEach(channel => channel.delete())
But nothing happens and I get 0 errors.
What you attempted is actually the solution.
You can use it on the message object, which means it's an action after you make a message, like so:
client.on('message', message => {
if (message.content === '.deleteChannels') {
message.guild.channels.forEach(channel => channel.delete());
}
});
triggered by making a discord message containing ".deleteChannels"
Make sure your bot has permissions to delete channels as well.
Be aware that this is a reply to a message. Otherwise, message would not be defined.
discord.js v12+ uses Managers, which means you'll have to go through an extra step and pass through the cache property.
msg.guild.channels.cache.forEach(channel => channel.delete());
Guide to switch from v11 to v12
More info about updating
I try to make my bot on Discord server. Want to make a function, which will copy all deleted message in text channel, but, messageDelete hear only deleted message which was writing after bot start. When I delete message which make earlier bot start, its not work.
{
client.on ("messageDelete", messageDelete =>{
let channel = client.channels.find(channel => channel.name === 'log-deleted-message')
console.log(`Deleted :${messageDelete.content}`)
channel.send(`${messageDelete.author.username} write : ${messageDelete.content}`
})
}
The above answer is now outdated.
With Discord.js V12 you can now Cache messages on the messageDelete event, You would need to enable Partials. Once this is enabled, you can fetch the message beforehand like this:
if(message.partial){
let msg = await message.fetch()
console.log(msg.content)
}
That will then log the content of the previously uncached message.
messageDelete is an event that is called when a message is deleted while the bot is on. If a message is deleted before the bot is turned on there is no way to recover it, which is why it's known as deleted. The only way to accomplish the goal that you want is to leave the bot on permanently. Read more in the docs if you want more information.