Discord.js bot command to take users with a specific role and to return an embedded message with all the users in that role - discord

I've been working on this and I cannot figure out why the bot will not enact the command. Essentially this is how the situation should work:
In the channel you send a message: "!listroletest"
After that, the bot should send an embedded with every user who has the role "test" with their userID's
client.on("message", message => {
if(message.content == "!listroletest") {
const ListEmbed = new Discord.MessageEmbed()
.setTitle('Users with the test role:')
.setDescription(message.guild.roles.get('901592912171765850').members.map(m=>m.user.tag).join('\n'));
message.channel.send(ListEmbed);
}
});

Related

Discord: Reading messages from one channel in a (non-admin perm) server, and posting it to another (with admin perms)

I am new to Discord API framework.
ServerFROM is a public server that I was invited to (non-admin perms). Hence I cannot add bots there. But I can view the content in ChannelFROM (a text channel in ServerFROM)
I have my own ServerTO (in which I have admin perms and so can do anything). Inside of which, I have the target ChannelTO
I want to deploy a listener on ChannelFROM, such when there is a new message (announcement) in ChannelFROM, I want it to be read and reposted in ChannelTO.
Something similar to what is done in this Stackoverflow issue, except that I cannot have some script run locally 24x7 on my machine. Maybe use Github Actions or something similar?
How can I go about doing it? Any ideas are appreciated. Maybe some form of a server, or just a custom Discord bot
And thanks in advance.
you can use Custom bot for that. I dont know other way
here's how i do it
1st : We Get the ID of the Channel that you wanted to listen
2nd : We make a Output or where the bot copy the message from and send it
3rd : Bot required a permission to view the channel and send message
or in the nutshell ( sorry if im bad at explaining )
client.on("messageCreate", message => {
if(message.author.bot) return;
if(message.channel.id === ID_HERE) // ChannelFROM in ID_HERE
{
let MSG = message.content
let Author = message.member.displayName
let Avatar = message.author.displayAvatarURL({dynamic: true})
const Embed = new MessageEmbed()
.setAuthor(Author , Avatar )
.setDescription(MSG)
.setColor("RANDOM")
client.channels.cache.get(ID_HERE).send({ embeds: [Embed] }) // SendTo in ID_HERE
}
})
you can remove if(message.author.bot) return; if you want it also read other bot message on that specific channel

Check if a user with a specific role reacted the latest bot message | Discord.js

i need to make my bot check if someone with admin role or a specific role reacted the bot's latest message
i made a suggestion command for my bot and i want to the bot check if anyone with the #Admin role reacted the latest bot message of #suggestions channel, then when a user that has the #Admin role react the suggestion, make the bot send me a DM saying something like: Accepted your suggestion!
Here is something that may help:
client.on('messageReactionAdd', async (reaction, user) {
if(reaction.message.channel.id !== 'suggestion channel id') return;
let channel = reaction.message.channel;
let msg = await channel.messages.fetch({limit: 1});
if(!msg || msg.id !== reaction.message.id) return;
if(reaction.message.guild.member(user).roles.cache.some(r => r.id === 'admin role id')) {
user.send('Your suggestion was accepted.')
//You may have said this wrong, but if you want the person who suggested it to be DMd
//You will need to somehow save their name (or id which can never change), let’s say you put it in the footer of an embed for the suggestion
let userID = reaction.message.embeds[0].footer;
msg.guild.members.cache.find(m => m.user.id === userID).send('Accepted your suggestion!')
}
})
I’d like to know if this doesn’t work because I didn’t get to test it. It may have some errors, but hopefully not

discordjs problems logging whenever a dm is sent

I have a whole logging system that logs whenever various things are done in the server or with the bot, one being a log of whenever a dm is sent to the bot. the log would contain the author ID and the message content. the problem is with logging the message content. the bot crashes whenever a second DM is sent but works fine if its a first DM. the bot crash message is the following: https://gyazo.com/5ad0b41648f83a855ac8c49fb220a612
but the strange thing is, my fields aren't empty:
bot.on('message', msg=>{
const LogChannel = bot.channels.cache.get('712811824826941460');
const LogEmbed = new Discord.MessageEmbed()
.setColor('#606060')
.setAuthor(msg.author.tag)
.setDescription('DM Sent')
.addField('Message', msg.content)
.setTimestamp()
if(msg.channel.type === 'dm')
LogChannel.send(LogEmbed)
});
the console thinks that the .addField('Message', msg.content) is empty but as you can see, it's not. keep in mind it only gives me the error message after a second DM is sent following a first one.
any ideas?
There is no Message.content properties. I guess you are looking for Message.cleanContent
bot.on('message', msg=>{
const LogChannel = bot.channels.cache.get('712811824826941460');
const LogEmbed = new Discord.MessageEmbed()
.setColor('#606060')
.setAuthor(msg.author.tag)
.setDescription('DM Sent')
.addField('Message', msg.cleanContent)
.setTimestamp()
if(msg.channel.type === 'dm')
LogChannel.send(LogEmbed)
});

How can I get my bot to DM a specific user on command?

I am wondering if my bot can send me a direct message after a user has sent a command. For example, let’s say a user sends a command and the bot replies to the user a message saying please wait for admin while the bot also sends me a direct message saying a user has requested for help. If there isn’t any way I can make that happen is there any similar way I can do that?
You can send DMs like this:
user.send("Your message");
So it would look like this:
const Discord = require("discord.js");
let client = new Discord.Client(),
prefix = "!";
client.on("message", (message) => {
if (message.content.startsWith(prefix)) {
let args = message.content.slice(prefix.length).split(" "),
cmd = args.shift();
if (cmd === "your_command") {
message.author.send("please wait for admin");
client.users.cache.get("your_user_id").send("a user has requested for help");
}
}
});

How to create a discord bot that only allows a specific word in a certain text channel

I am trying to create a discord bot that only allows the word "upgrade" in a certain text channel.
As I am very new to this I would like to learn about how this is done.
Its easy. First create a bot. I guess you know about node.js if not, find tutorials for creating a project with discord.js.
First create a client:
const Discord = require("discord.js");
const client = new Discord.Client();
client.login("SuperSecretBotTokenHere");
(make sure you have a bot token) discordapp.com/developers
Then you create a message event:
client.on("message", (message) => {
if(message.content != "upgrade") return message.delete()
});
Put your bot in the server, give it permissions to delete messages in the channel aaand done!
Sorry for my bad English.

Resources