I want to make a command where, if someone types "?role #testrole", the bot will send an embed with a list of users who have the aforementioned role.
An example response would be:
List of #testrole
- #Adam
- #Drago
- #Santiago
Here's my code:
if (message.content.toLowerCase() == 'teamone') {
let team1 = message.guild.member(
message.member.roles.cache.has('750579457953234994')
);
message.channel.send({
embed: {
title: 'Team 1 composition!',
description: `${team1}`,
},
});
}
I tried but it does not work, it only sends null. Any ideas?
Try this:
if (message.content.toLowerCase() == 'teamone') {
let team1 = message.guild.roles.cache
.get('750579457953234994') // get the role in question
.members.map((member) => `<#${member.id}>`) // map the results in mention format (<#${user.id}>)
.join('\n'); // join by a line break
message.channel.send({
embed: {
title: 'Team 1 composition!',
description: `${team1}`,
},
});
}
Every Role has a members property, which is a collection of all (cached) members that have the given role.
You can then use the Collection.prototype.map function to format each member to a mention. Here's an example from my server:
(I used the mod role as an example, this is my mod team)
Related
So I am in the process of making a Discord.Js bot that includes a command that will let me provide information on certain users. For example: I want to add a command that will provide the PlayStation gamer tag of a mentioned user (lets say the specific users id is <#123>). The input message would look something like this :
"!psn #mention" then the bot would output his gamertag which I will manually log as--> message.channel.send('Here is <#1235467890> 's #psnname');
I want to include the gamertag every member in my server so anyone can request it upon mentioning it with the command "psn", I have gone through tons of trial and error with different code but i can not figure out how to specify the message.mention.members.first(); by a specific user id. Please help
module.exports = {
name: 'codtag',
execute(message, args){
let member = message.mentions.members.first();
if(!args.length){
return message.channel.send({embed: {
color: '#da1801',
title: 'Activision Gamertag: Error',
description: 'You need to tag a user dummy.'
}})
}
if (member !== '<#772597378142306354>')return;
else if (member === `772597378142306354`)return
{
(args[0] === member)
return message.channel.send({embed: {
color: '#1243c6',
title: 'Activision Gamertag',
description: 'Here is <#772597378142306354> Activision: \n\n **WalterWhite#2396124**'
}});
}}
}
For anyone that finds this post with the same question, I figured it out. The following code works perfectly
I added:
let guild = message.mentions.members.first();
I also included the condition for args[0] as:
if (message.mentions.members.had('put users id here without the <#>')
module.exports = {
name: 'cod',
execute(message, args){
let guild = message.mentions.members.first();
if(!args.length){
return message.channel.send({embed: {
color: '#da1801',
title: 'Activision Gamertag: Error',
description: 'You need to tag a valid user dummy.'
}})
}
if(message.mentions.members.has('772597378142306354')){
(args[0] == guild)
message.channel.send({embed: {
color: '#1243c6',
title: 'Activision Gamertag',
description: 'Here is <#772597378142306354> Activision: \n\n **WalterWhite#2396124**',
footer: {
text: 'Message #issmayo if your gamertag is not included.'
}
}});
}
I'm using Node.JS to create a discord bot in which a new role and channel are created with the same command. For the sake of simplicity, both the name of the role and the name of the channel are the first argument of the command:
let chanName = args[0];
let roleName = args[0];
Following the name of the role/channel is a list of mentions - these are the users that receive the new role. The role is created just fine, the channel is created just fine, and the members are added to the role just fine, but I'm having trouble setting up permissions where only users with the new role OR the 'administrator' role are able to see the channel.
The channel is created like so:
message.guild.channels.create(chanName, {
type: "text"
})
.then((channel) => {
//Each new channel is created under the same category
const categoryID = '18-digit-category-id';
channel.setParent(categoryID);
})
.catch(console.error);
It appears as though the channel is not added to the guild cache
let chan = message.guild.channels.cache.find(channel => channel.name === chanName);
because this code returns 'undefined' to the console.
Is there any way I can allow the mentioned users to interact (view, send messages, add reactions...) with this new channel?
Permissions are very simple to set up upon creating a channel!
Thanks to the multiple options GuildChannelManager#create() gives us, we're very simply able to add permission overwrites to our desired roles and members.
We could very simply take your code and add a permissionOverwrites section to set the channel's permissions, as follows:
message.guild.channels.create(chanName, {
type: "text",
permissionOverwrites: [
// keep in mind permissionOverwrites work off id's!
{
id: role.id, // "role" obviously resembles the role object you've just created
allow: ['VIEW_CHANNEL']
},
{
id: administratorRole.id, // "administratorRole" obviously resembles your Administrator Role object
allow: ['VIEW_CHANNEL']
},
{
id: message.guild.id,
deny: ['VIEW_CHANNEL']
}
]
})
.then((channel) => {
//Each new channel is created under the same category
const categoryID = '18-digit-category-id';
channel.setParent(categoryID);
})
I'm trying to create a bot, and one of its commands is user-info
for eg. !user-info #<username>
and i want it to display username, id and the avatar
like:
username:<username>
Id:<User Id>
Avatar:<the avatar >
Below is the code i used:
else if (message.content.startsWith(`${prefix}user-info`)) {
var member = message.mentions.users.first();
message.channel.send(`Username: ${member.username}\n ID:${member.id}\n Avatar:${member.displayAvatarURL()}` );
}
However it doesn't work, when i remove the avatar part the output comes out as :
Username:undefined
Id:<the id>
When I add the avatar part I just get a huge error on the command module when I use the bot command. What's the right way and what did I get wrong?
I'd suggest you use an Embed for this, as those can display images in a better way, the code for your request would be:
var user = message.mentions.users.first();
message.channel.send({
embed: {
title: `Profile of ${user.tag}`,
thumbnail: {
url: user.displayAvatarURL(),
},
fields: [
{
title: "ID:",
value: user.id
}
]
}
});
You can find more on this here
Well, I'm currently using the emoji :x:, but on my server I have an emoji called :superbotxemoji: I just don't know how I get my bot to use it
My code:
const Discord = require('discord.js');
module.exports = {
name: 'say',
description: 'say',
execute(message, args) {
const { prefix, token } = require('../config.json');
if (!message.member.hasPermission('ADMINISTRATOR'))
return message.channel.send({
embed: {
color: 16777201,
description: `:x: | ${message.author}, You are not allowed to use this command.`,
footer: {
text: ` | Required permission: ADMINISTRATOR`,
},
},
});
if (!args.length)
return message.channel.send({
embed: {
color: 16777201,
description: `:x: | ${message.author}, You need to put a message.`,
footer: {
text: ` | Example: !say hello`,
},
},
});
const sayMessage = args.join(' ');
message.delete({ timeout: 1 });
message.channel.send(sayMessage);
},
};
There is actually a very detailed explanation from the official discord.js guide which you can find here, although I'll try to paraphrase it.
To send a custom emoji, you must get that emoji's unique ID. To find that, you must send the emote in discord with a backslash in front of it; essentially escaping the emoji.
This will result in the emojis unique ID in this format: <:emoji-name:emoji-id>
If you paste this special string into a message, the bot will send the emoji. However, the emoji must be from a guild the bot is part of.
On the other hand, there's another very easy way to get an emoji using the client.emojis.cache collection and the .find() method.
client.emojis.cache.find(emoji => emoji.name === '<name of emoji>')
This method will also make it possible to send custom emojis, however, this time you can find them by name. Be careful, if there are more than one emojis by the given name, it will not work.
A way to bypass this problem would be looking at a guild.emojis.cache collection. This way the amount of possible duplicate emojis would be narrowed down.
I'm trying to create slack like application using getstream.io chat SDK. In the documentation we can find out, how to initiate a channel to start group chat. But there is no any information about one-to-one chat. Does anyone knows how to initiate a one-to-one chat?
code sample to create new channel for group chat
const client = new StreamChat('t5v25xyujjjq');
await client.setUser(
{
id: 'jlahey',
name: 'Jim Lahey',
image: 'https://i.imgur.com/fR9Jz14.png',
},
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiamxhaGV5In0.sFe9WvuHIKgQmgtEWFh708Nu_a2wy8Zj3Q8BJz7fDRY',
);
const channel = chatClient.channel('messaging', 'groupname', {
name: 'Founder Chat',
image: 'profile image url',
members: ['user1', 'user2'],
});
const response = await channel.sendMessage({
text: 'Josh I told them I was pesca-pescatarian'
});
If you want to have the guarantee that only one channel exists between N users you can instantiate the Channel without ID and the list of its members.
When you do that, the API will ensure that only one channel with the list of members exists (order of the members does not matter).
const distinctChannel = conversation.channel("messaging","", {
members: [user1.id, user2.id],
});
await distinctChannel.create();
Since the channel data is going to be the same for both members; I suggest to not store the image field the way you do in your code example. It is easier to use the "other" member profile image as the channel image when you render the conversation.
For example:
let channelImage = "https://path/to/fallback/image";
otherMembers = channel.members.filter(member => member.user.id != currentUser.id);
if otherMembers.length > 0 {
channelImage = otherMembers[0].image;
}
Check the docs securely, it's in there:
check under channel initialization
const conversation = authClient.channel('messaging', 'thierry-tommaso-1', {
name: 'Founder Chat',
image: 'bit.ly/2O35mws',
members: ['thierry', 'tommaso'],
});