Hey I recently started programming a discord bot. But now I have a problem. I'm trying to get a role reaction but somehow I keep getting errors. I'm going to link you errors and my code so maybe someone can help me.
Warnings: https://hastebin.com/ativekefod.sql
MessageReactionAddEvent.js: https://hastebin.com/nababomuta.js
Thanks for any help!
you are retrieving 3 parameters when only 2 are given, messageReaction and user,
https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-messageReactionAdd
So essentially you are calling .message on a user class.
Change the run function to:
async run(client, reaction, user);
And then your message variable would be:
const message = reaction.message;
It's possible it's different depending on your event handler but this is most likely it
Related
I am trying to create a channel, with only one single person cappable to see it.
I use permissionOverwrites to give permissions to certain users but Im getting this error:
"TypeError [InvalidType]: Supplied parameter is not a User nor a Role."
I tried to set a user ID hardcoded so I AM sure that Im putting a right ID.
My code works fine if I use a role ID, but I need to use a user ID for all cost.
This is what happened:
(My code and error)
Thank you in advance for your help. <3
EDIT:
I tried this:
server.members.fetch()
.then(member => console.log(member));
And it prints nothing.
I got the solution!
The problem was that the client needs the intent GuildPresence.
GatewayIntentBits.GuildPresences
Im getting a message that got reacted with a emoji, and want to send it in another channel, but I cant get the embed information from that message reaction.message.embeds is empty.
Do I need to set some intents to be able to read that data? Like GatewayIntentsBits.MessageContent for messages
Want to re-send a message with embed to another channel
[EDIT]
When I do some weird shit: reaction.message.channel.messages.fetch(reaction.message.id) the embeds tag seems to work, is there any way or reason for that? Or should I use this weird way, can someone explain to me why the first example doesnt work?
In regards of the Intents:
This property requires the GatewayIntentBits.MessageContent privileged intent in a guild for messages that do not mention the client. (https://discord.js.org/#/docs/discord.js/main/class/Message?scrollTo=embeds)
The return is an Array of embeds. Therefore you would need to access it with reaction.message.embeds[0] for example. Of course if your reaction.message.embedsis completly empty this would not help.
A good way to check for the information is to console.log(reaction.message)
You can also fetch() the reaction directly to get the full MessageReaction information.
reaction.fetch().then((fetchedReaction) => {
fetchedReaction.message.embeds[0]; //or
fetchedReaction.message.embeds;
});
Your solution
reaction.message.channel.messages.fetch(reaction.message.id)
is indeed the best and correct way if the message may not be in the cache. This way it is still being retrived.
I've been trying to make slash commands in discord.js for a discord bot (a personal project to practice coding) and I've been getting this error, with no success in trying to solve it... I've already given OAuth2 access to the command creation, so I have no idea what I'm doing wrong.
https://pastebin.com/y5g2P8Cm
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\Users\Nicolò\Desktop\colino-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\Nicolò\Desktop\colino-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:99:20) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'put',
url: 'https://discord.com/api/v9/applications/914567485158744104/guilds/251345856169508864/commands'
}
EDIT: Solved, apparently I just removed some permissions and now it works... I have no clue why it works this way, but ok.
When your bot is added to a server via an OAuth2 link it requires the application.commands to be able to register slash commands.
Even if you update the scopes in your link the bot has to be removed and then re-added back to the server with the new link for the changes to take effect.
Learn more about discord OAauth2 scopes here
EDIT: Solved, apparently I just removed some permissions and now it works... I have no clue why it works this way, but ok.
Anyone encountering this problem the solution is pretty simple.
It DOES NOT depend on the permissions that have been provided to the bot when creating the OAuth2 link to invite the bot. It is not enough to just select the bot option, the applications.commands option also needs to be selected, see captured screenshot in the following link
I have a discord bot, in JavaScript and I was wondering how I could make it so when a user ran a message which only contained the bots mention, it would respond with a message such as The server prefix is... <prefix>.
I have tried adding this in the prefix file but nothing actually happened when I mentioned the bot.
if (message.content.startsWith("<#649042475557584896>") {
return message.channel.send(`The server prefix is... ${args[0]}`)
}.
I even tried setting it in an embed, to make it cleaner but that didnt help either.
You can use the propertie isMemberMentioned() from the Message object.
Little example:
client.on("message", (message) => {
if (message.isMemberMentioned(client.user)){
//do your code here...
}
}
WARNING! It seems it's deprecated. V12 seems to don't work with it.
https://discord.js.org/#/docs/main/v11/class/Message?scrollTo=isMemberMentioned
I'm trying to implement a command for my bot that gives a role to a user for a determined amount of time, but I don't know how to make the bot remove or add a role to a user.
I need it to involve the server ID cause I plan on using the bot in multiple servers.
This is clearly wrong, but I hope it can help you all understand what I'm trying to do:
client.guilds.get(config.serverID).message.guild.members.get(userID).removeRole(config.donatorRole)
You almost have it! The only thing wrong is that message isn't a property of a Guild. Also, make sure to catch any errors if the Promise returned by GuildMember.removeRole() is rejected.
Here's a cleaned up example:
const guild = client.guilds.get(config.serverID);
const member = guild.members.get(userID);
member.removeRole(config.donatorRole)
.catch(console.error);