Discord.js Bot that can send a embed message - discord

I will refer to this picture:
I am making a Discord bot in JavaScript and I am stuck somewhere
I have a say command which you use like !say Text here and the bot will send a plain message saying Text here
Now I want the bot to send an embed message used the same and I want the bot to have a title, image, link and a author set on default. When someone does !sayEmbed #everyone loco (the text there)

There you go:
client.on("message", function(msg){
if (msg.content.split("!")[0] != "sayEmbed") return;
if (msg.content.split(" ")[1]){
// if args exist
msg.channel.send(new MessageEmbed()
.setTitle("Genius Mind")
.setDescription(msg.content.split("!sayEmbed")[0])
.setColor("#148837")
.setAuthor(`#everyone react now | {msg.createdAt.toDateString}`)
.setURL("someURL.example.com")
.setThumbnail("foo.bar/link/to/image")
)
}
}
I couldn't find any url and image url, so change that yourself.

Related

can my bot reply with a message when pinged only

when I ping my discord bot it shows what I made it say, but when someone replies to the bot it still sends the message, I want it to reply only when pinged.
You could add this into your messageCreateevent:
if (message.mentions.has(client.user.id)) return message.channel.send({ content: `My Prefix is ${prefix}` });
You should define your prefix first so it wont get called as undefined and for the bot to show your prefix.
For more information about Discord.js mention: discord.js documentation

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

Approval/Denial System using Discord.js

DISCORD.JS
Hey! So, recently, I was on a server that contained an amazing bot. That was an approval or denial system. So, what would happen for example, somebody would sign a google form and the google script will send the response via a webhook (I already know that code) in an embed to a private channel named "awaiting-result", now, the bot will automatically add reactions to the message, for example, ✅ and ❌. Then, a staff member will react with either one of those emojis and it will send to two different channels. If the reaction was a ✅, then the bot will remove all reactions from the original message, copy the exact embed from the google form response, and send it to a channel named "accepted-logs" with a message above it "Your log has been accepted by ${person}". If it was an ❌, it will do the exact same thing as the approved one. I have been trying hard, but cant find it. All I ready need is the bot code, not the form script. So basically, you react, copy the exact embed, send to another channel. Itll be very helpful, thanks!
List of useful links:
https://discordjs.guide/popular-topics/reactions.html#unicode-emojis
https://discordjs.guide/popular-topics/collectors.html#reaction-collectors
https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor
I'm pretty sure you could just store the embed contents in an Object, then you can wait for the collector to collect a ✅ or ❌, check if the user has admin role (e.t.c), and then find the channel the embed needs to be sent too
let channel = client.channels.cache.find(channel => channel.name === "name");
and then you can send the embed to the channel via
channel.send(embed);
In order to make an embed, you just do:
let embed = new Discord.MessageEmbed();
And then you can add fields to it (see link #3). Then you can simply just do
let approvalChannel = client.channels.cache.find(channel => channel.name = "admin-approval");
approvalChannel.send(embed);
// Code for reaction collector

how to make it so that if a message is dm'ed a bot the message is shown in a channel in server discord.js

I need help making a discord bot so that if a message is dm'ed a bot the message is shown in a channel in server discord.js
A very basic way to do this is to just see if the message channel type is a DM (if (message.channel.type === 'dm')), and if it is, we will send the message content to a certain channel (client.channels.cache.get('channel_id').send(message.content)).
Put together, it is like this:
if (message.channel.type === 'dm') {
client.channels.cache.get('channel_id').send(message.content)
}
That will only send the message content.If you want to see who sent the message, you can do something like this:
client.channels.cache.get('channel_id').send(`New message by ${message.author.tag}: ${message.content}`)
This well send you something like New message by Username#0000: Hello world!.(This is a good place to stop if you want a simple if statement that gets who sent it and the message content.)
We can then go on to create this as an embed:
var dmMessage = new Discord.MessageEmbed() // This creates an empty embed
.setTitle("New DM!") // This sets the title of the embed to 'New DM!'
.setDescription(`**New message from ${message.author.tag}**(${message.author.id})\n**Message content**: ${message.content}`) // This is the main text of the embed
.setColor("GREEN") // This sets the color of the embed. It can be RED, PURPLE, etc. or it can be a hex code
.setTimestamp() // This shows the time when the embed was sent. ( it would also be the time the message was sent )
.setFooter(client.user.tag, client.user.displayAvatarURL()) // This sets the bots tag and profile picture to the footer
.setAuthor(message.author.tag, message.author.displayAvatarURL({dynamic: true})) // This sets the 'author' of the embed. It will show up at the top of the embed. The {dynamic: true} just makes it animate the profile photo if it is animated
if (message.channel.type === 'dm') {
client.channels.cache.get('channel_id').send(dmMessage) // Sends the embed to the specified channel ID
}
You can always create a variable like var dmID = "your_channel_id" and replace the 'channel_id' in the client.channels.cache.get with dmID so you can change the variable and it will change everywhere.

I can't fetch the avatar of author through discord js

I want to fetch the avatar picture of the person who sends the message through a Discord bot. Like the author of the message.
This is my code:
case 'embed':
const embed = new Discord.MessageEmbed()
.setAuthor(`From ${message.author.username}`, message.author.avatarURL)
.setDescription("My Description");
message.channel.send(embed);
break;
It returns the author's username correctly through message.author.username but when I am using message.author.avatarURL it's not returning anything. I had tried to use message.author.defaultAvatarURL and it works perfectly. But I don't know why avatarURL doesn't show up anything.
In discord.js v12 User#avatarURL is a method, not a property, and so you need to call it to get the URL. You can also use User#displayAvatarURL to get the either the actual displayed avatar (it links to the default avatar if necessary). Here's an example:
.setAuthor(`From ${message.author.username}`, message.author.avatarURL())
.setAuthor(`From ${message.author.username}`, message.author.displayAvatarURL())

Resources