Discord.js GuildMember.hasPermission? - javascript

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.

Related

In my userinfo command how should i do that I don’t have to use the ID of the person and ping them. It will show the info of the person using the cmd

I want to make it so when i execute the command without pinging or using the ID of the person it will show the userinfo of the person using the command.
You will have to check message.mentions.members.first(). If it's undefined then use the message's author - message.author.
But it's hard to help and give suggestions without showing us what you have made so far.

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.

Discord.js check role existence

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.

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

Categories