Discord.js check role existence - javascript

So as I said in my last stackoverflow question about discord.js they recently updated and I want to know how to check if a member have a role. You must know that message.guild.member(message.author).roles.has("688366821895700480") won't work.
Thanks in advance!

On Discord.js v11.x it's:
message.member.roles.has()
On v12.x it's
message.member.roles.cache.has()
Be aware that this will only work if the message does come from a guild. Test message.member for undefined if it is unknown.
You can do it the way you were attempting by going through the guild object, but it's more complex than it needs to be compared to using the above method.

Related

How would I mention someone In Discord JS

I want to be able to mention a user when they join the server I really need help with this.
For user mentions it is the user's ID with <# at the start and > at the end,
like this:
<#17372382352635>
I figured out how to do it I will help some of you guys so when you are making it put the tilda key instead of ''.
You'll need the following method guildMemberAdd from Discord.js
bot.on('guildMemberAdd', async (guild_member) => {
//message.send with notification, for `guild_member.user.username`
})
You may also find the example code, in the repo of my own Discord bot, which is actually check (for proper names) and renaming users, on server join event.
My personal advice, not to use DM (because users may have forbid to receive messages from non-friends and members of the mutual discord server.
And as was mentioned before, by Dpk, you may use <#idOfUser/Channel/Whatever> to create a link or mention or any other thing via it's ID.

What is the best way to create a Reaction Roll function for my discord bot using discord.js?

I have been trying to do this for some time, but to no luck.
I am fairly new javascript so am not very competent at it.
I essentially want it to work like the reaction roles bot:
It asks which channel to add the reaction roles to,
you reply with '#general' for instance.
Then it asks which message you want to add it too,
you reply with the '[message ID]' you want the reaction roles added to.
Then it asks which emoji to react with to get the role,
you reply with that emoji (also include failsafe in case its a nitro only emoji).
Then it asks for which role to give the person,
you reply with something like '#moderator'.
Finally it asks if you want to receive the roll (1) from clicking on it or remove the roll (2) from the user.
you reply with either '1' or '2'
Then it will add the reaction to the message and that should be it and it would work.
Any help at all is welcome,
even if it only contributes to a small part of this,
I am aware after programming on other languages it is never easy to make these things.
Thank you everyone!
The tutorial that Delight posted started me off on a long journey of discovery.
After much research I have found the best way to make it was by following this tutorial:
https://www.youtube.com/watch?v=2CCGwsbNaSc&list=PL_cUvD4qzbkxKEHA-_CFmEG0Y2qQCqYFT&index=1
Which helped integrate a Database also.
Also the person making the video was very very good at explaining what they did and walked you through it, allowing me to make all the changes I wanted to with no problems.
I can't possibly explain the stuff as well as this person, so if you want to make a good reaction roles bot please look at that guys tutorials. :)
I would use
client.on("messageReactionAdd", reaction => {
});
to detect if someone reacted to a message. Then I would check if the message was a reaction role message and add the role if everything looks ok. You might wanna check out this tutorial on reaction roles.

Re-create channel with same permissions

I am trying to create a bot that re-creates a channel with the same permissions.
So my current code re-creates the channel fine in the same position, NSFW value, etc. but it doesn't put the permissions of the old channel into the new one :/
I've been searching the whole day but couldn't solve it.
I didn't know that Discord.js had a .clone method for GuildChannel
This is more easier now based on the documentation :-)
I am pretty sure this could help you:
recreatedchannel.replacePermissionOverwrites({ overwrites: firstChannel.permissionOverwrites });
You basically overwrite the permissions of the new channel with the permissions of the channel you are recreating. Always worked for me :)
Question
I don't think this is possible. And anyways couldn't you just clone the channel. The reasoning behind the bot I don't really understand. Will you tell me the reasoning. Is your discord server a roleplay server?
You can see how to clone a server at Facebook Pro Tippy Clone Channel!

Create a group DM Discord.js

I am trying to get my bot to message two people but in the same chat window (like when you add a friend to a conversation). The only thing I've found is how to send to a single person by doing <client>.send(message); How could I add a second person to that conversation?
Any examples would be highly appreciated.
Discord.js doesn't really implement that because in Discord bots can't join Group DMs. You would need a self-bot (a bot that runs on a user account), but Discord doesn't want them to be used, so discord.js didn't make this options.
Therefore, at the moment there's no way to do that: the groupDMChannel class can't be used to create them, and since there's no method to do that from the client or from a DM channel I think you're stuck there :\
just taking a quick look at the Discord.js documentation, it seems they do have a GroupDMChannel class, and this seems to be what you want / need to use.
The two methods that stand out to me:
send
addUser
Where I'm assuming (I know I shouldn't!) that you have to call addUser first.
disclaimer: not going into detail, since I don't have experience using this particular module

Discord.js GuildMember.hasPermission?

I'm trying to make a warn command for my discord bot but the system I made for non admins to not be able to use it doesn't really work because of the msg.guildmember.haspermission thing. I'm not sure what's going wrong can anyone help me out here?
Use member instead of GuildMember at lines 6 and 7 in the screenshot.
I'd also suggest checking out Discord's official API documentation and the discord.js documentation if you haven't already.
Looking at the API: msg doesn't have a GuildMember property it has a member so the line should be !msg.member.hasPermission('KICK_MEMBERS')
PS: you are not using the role variable in your screenshot.

Categories