Im trying to do a reaction role bot on discord - discord

client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.message.id === "731619243249893417"){
const guildMember = reaction.message.guild.members.cache.get(user.id)
if(!guildMember.roles.cache.get("692177977705889845")){
guildMember.roles.add("692177977705889845");
Im using this code, but when i react to the message it
don't give me the role, im a starter needing help, thanks u all, and sorry for my english

Bots only listen for new messages. You have to tell them to listen for an old message explicitly to get a reaction from them. Try using this code. It fetches the message when a reaction is added to that message.

Related

How to Introduce the Bot [On added to server]

I have a question regarding on how to detect if my discord bot was added to a server. I want to display an embed when they are added, an example would be:
Can someone tell me how to do this? Thanks.
You can use the
<Client>.on('guildCreate') event.
https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-guildCreate
It's simple
I suppose you want to send a message in the guild when the bot is added
client.on("guildCreate", async (guild) =>{
guild.systemChannel.send({content: `Thank's for adding me into your server`})
})

discord.js access to existing message and get reaction count

Hope you could help me a bit on this. I'm trying to code a small function but I am sure to miss something quite obvious here... I tried with the help of many previous messages, but most of them are old discord.js version (I'm on V13)
My code goal is : from the ID of a message, i would like to catch the number of reactions of a specific emoji. I must precise that this is on existing message, not on the event of new message arriving or new reaction. It will be triggered by a cron function.
Other precision : The message will be posted & reacted after the bot is online
channel = client.get_channel(CHAN_CHALLENGE_ID);
message = await channel.fetch_message(messageID);
MyValue == message.reactions.cache.find(reaction => reaction.emoji.name == MyEmoji).count;
I get the error code "client.get_channel" is not a function
Thank you very much in advance for your help !!!
Get Channel
Discord.js: GuildChannelManager
const channel = guild.channels.cache.get('CHANNEL ID');
Get Message
Discord.js: TextChannel: messages
const message = await channel.messages.fetch('MESSAGE ID');

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

Discord,js bot making a channel

I am trying to make my discord bot create a channel! I have tried many way's but none of them work! Note: this is discord.js! Here is the code I have come up with! IT DOES NOT WORK!
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
'guild' must be defined in some way. You can get it from a message for example by using message.guild or even by its name using client.guilds.find(guild => guild.name === "Guild Name");

Creating a Discord bot to notify people when to certain text on a website has changed

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', msg=>{
if(msg.content === "?rates"){
msg.reply('.')
}
})
bot.login(token);
This is what I have so far it is very basic, I understand, I'm just trying to get some sort of idea how to process. What I want is as soon as a website gets updated or changed. I would like it to tag everyone and in a certain channel and specifies what has changed. I know this will be a long process but I'm in for the ride :) would appreciate any help.
You need a webhook on the website and listen to it with your bot, if you have control over the site, this may help you, otherwise you could look if the site has one or perhaps ask an owner.
A probably working but not very nice (and not very clean) solution would be to save the text of the website every 5 seconds or so and compare it to the previous save. If it changed, you notify the members through sending a message.

Resources