how to mention current channel to another channel - javascript

I'd like it so when I type .done it'll send the channel the command was ran in, and send it to another channel. It needs to be mentioned (Clickable) The current code I have doesn't mention the channel, but only the channel’s name. I have no idea what I'm doing, I've just been copying from the internet.
if (command == "done")
return client.channels.cache.get('744836547391652000') .send(message.channel.send)

To mention a channel you need to convert it to a string using the channel's .toString() method. Or simply use template literals like this:
client.channels.cache.get("744836547391652000").send(`${message.channel}`);

Related

How do you make a Discord bot send an emoji when you give it the name of the emoji?

I'm trying to make my Discord bot send an emoji when I tell it the name. E.g., say I send !emoji hello, I want the bot to send back the emoji called hello.
If I send an emoji the bot will send it back but I'm not sure how to grab an emoji from its name being sent to the bot.
I use discord.js v12 for reference.
You could try something like this
bot.on("messageCreate", (message) => {
const exampleEmoji = message.guild.emojis.cache.find(emoji => emoji.name === message.content);
channel.message.send(`Is this the emoji you want? ${exampleEmoji}`);
});
You can then nest it inside of your if statement as you please with whatever command you are using. This also should be v12/v13 compatible and I believe the only differences with older versions is whether you add cache or not to the find function.
You can also use the same function to find the emoji as a boolean to determine if the emoji exists or not and if not send a different message for feedback.
I also found this really interesting function which helped me when deciphering which emojis I have and which are not in the scope I am presenting.
if (message.content === "listemojis") {
const emojiList = message.guild.emojis.cache.map((e, x) => `${x} = ${e} | ${e.name}`).join("\n");
message.channel.send(emojiList);
}
Which will output this for every emoji within the scope you searched.
450661466287112204 = :image: | name
Which I found here.
Hope this helps

Get information about the mentioned user / message author with discord.js

**• Server Roles:** <#&${user._roles.join('> <#&')}>,
^^ Cannot read property 'join' of undefined
I used message.member._roles.join('> <#&')}>`,
But it always showed the roles of the user that wrote the command, and not the user that you mentioned.
Message.member is user who sent this message.
If you want to get mentioned guild members you need to use message.mentions.members
which returns an collection of mentioned users.
Your code should look like:
// To make sure that only one member is mentioned
if(message.mentions.members.size == 1){
const roles = `<#&${message.mentions.members.first()._roles.join('> <#&')}>`
message.channel.send(roles);
}
I recommend sending empty message first and then editing its content to add these mentions just to avoid pinging whole server.

Is there a way to bind a bot to one specific channel?

I am making a Discord bot, and want to make it only be able to post on 1 specific channel. I can not make it have a lower role than a regular member, or it will not be able to give them roles.
I have tried an if/else statement based on the channel's ID.
case 'start':
if (message.channel === 615842616373805067) {
//somewhat unimportant command
return message.member.addRole('615166824849604619'),
message.channel.send(` ${message.author} has been given the role.)`,
message.delete);
//unimportant command ends here
} else {
console.log('Wrong channel, no role.')
}
I expect the bot to only be able to post in this one channel.
Instead of checking for the message.channel Class, try checking for the id property of that class
if(message.channel.id != "615842616373805067") return console.log('Wrong channel, no role.');
//rest of your code
Make sure to check the official documentation for detailed descriptions of each Class, Method, Property, etc.

How to make a discord js bot send direct/private message not to author?

I am using node.js for discord.
After I make a command, I want my bot to send a direct/private message to a specific person, not the author who makes the command (me).
Right now I have the person's <#000000000000000000> (I think this is called an ID), which is in String format.
For instance, this code client.sendMessage(message.author, "Hello!"); sends the author the message Hello. But I want one like client.sendMessage(message.user("<#000000000000000000>"), "Hello!");
Does a function like that exist?
For background information, I'm making a werewolf game bot where players are randomly assigned a role, and after I command w!play I want the players to receive their roles in the DM.
Yes just get the user object and send to that. You will need their id, so parse out the id part of the string "<#0000>". Also, sendMessage is deprecated. Use channel.send(). In the case of a user:
let str = "<#123456789>"; //Just assuming some random tag.
//removing any sign of < # ! >...
//the exclamation symbol comes if the user has a nickname on the server.
let id = str.replace(/[<#!>]/g, '');
client.fetchUser(id)
.then(user => {user.send("Hello I dmed you!")})
I would not write it that way unless you have a reason for doing so specifically.
I have used webhooks with git for discord, used hashtags to communicate on a private channel, (and create dm channels) thus I can add in rules for deletion/exclusions (for admins or otherwise)
(This wouldn't be applicable to Facebook if you need Facebook integration)

Permissions in Discord.js API?

I'm coding a Discord bot with discord.js/node (I'm fairly new).
I tried to setup a permissions system where you would need a specific role to make an if statement return true and allow the user to use a command or something else. I tried (this is just part of it):
if(message.author.roles.includes('role_id') {
COMMANDS
}
But it just gives me errors in the console (obviously)
If any of you know how to properly set a permissions system up in a efficient way, that would be appreciated!
To achieve this using an if conditional: if(message.member.roles.has([role_id]))
where [role_id] is a string (otherwise it will always return false)
There is an hasRole method on users: http://discordjs.readthedocs.io/en/8.2.0/docs_user.html
hasRole(role)
Shortcut of client.memberHasRole(member, role)
See client.memberHasRole
Which link to this: http://discordjs.readthedocs.io/en/8.2.0/docs_client.html#memberhasrole-member-role
memberHasRole(member, role)
Returns if a user has a role
Did you try doing something like this?
if (!message.member.roles.some(r=>["role_name"].includes(r.name)) )
return;
This will prevent all users from using that specific command unless they have the specified role.

Categories

Resources