I am making a discord bot in js. I have a rich embed but I don't know how to react to it. The message.react('emoji name thing') doesn't work.
code:
var pollEmbed = new discord.RichEmbed()
.setTitle(message.author.username + " asks " + args)
.setAuthor(message.author.username)
message.channel.send(pollEmbed);
pollEmbed.react("✔")
Your problem is that you can't react to a RichEmbed object, only a message. Use the following code to react to the newly sent message instead...
message.channel.send(pollEmbed)
.then(m => m.react('✔'));
Related
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
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())
I am currently working on my discord bot that works a lot with emojis. But somehow I can not let my bot write more than two emojis.
This works:
case 'test':
embed = new Discord.MessageEmbed()
.setColor(hexColor)
.setDescription(`Two Emoji <:harold:620608308910358530> <a:nice:634785041762877441> ok.`)
message.channel.send(embed);
break;
The Emojis get displayed in the discord chat as usual.
However, if I do it with more emojis, like:
case 'test':
embed = new Discord.MessageEmbed()
.setColor(hexColor)
.setDescription(`Three Emoji <:harold:620608308910358530> <:harold:620608308910358530> <a:nice:634785041762877441> ok.`)
message.channel.send(embed);
break;
Discord automatically converts the bot's message to this:
Three Emoji :harold: :harold: :nice: ok.
So not the actual emojis are displayed anymore, just their names with : around them.
This prevents me including more than two custom emojis in a single message. Is there a way to prevent this from happening? Or is this just a known limitation from Discord's side?
When working with custom emojis, it is best to fetch the custom emojis before using it.
case 'test':
const haroldEmoji = client.emojis.cache.get('620608308910358530')
const niceEmoji = client.emojis.cache.get('634785041762877441')
embed = new Discord.MessageEmbed()
.setColor(hexColor)
.setDescription(`Three Emoji ${haroldEmoji} ${haroldEmoji} ${niceEmoji} ok.`)
message.channel.send(embed);
break;
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.
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.