I am trying making my bot change the nickname to Member when someone joins but I have no idea how to make that... If someone could help
EXAMPLE:
If a member named Noob join the bot will change it name to: [Member] Noob
Thanks in advance!
You should listen for guildMemberAdd and use .setNickname to update the nickname.
client.on('guildMemberAdd', member => {
member.setNickname('[Member] ' + member.displayName);
});
Related
so I am currently trying to find out if there is a way I could give a user a role by typing the a variable name. Like, example, '!role testrole', and then the bot will give them what the testrole is defined at. Like, 'if(args[1] === "testrole")...'. Testrole can just be defined as that, but the actual role name can just be like test. You can add multiple roles, and it will add it. '!role hello', etc...? Discord.JS
You can try something simple using a function to find the role name. You can do something like:
const roleName = message.guild.roles.cache.find(r => (r.name === args[1].toString()) || (r.id === args[1].toString().replace(/[^\w\s]/gi, '')));
This will either check for a mentioned role or a role name given
So, I'm trying to make a serverInfo command as you can see below
let embed = new Discord.MessageEmbed()
.setColor("GREEN")
.setTitle("Server Information")
.setDescription(`Server Name: **${message.guild.name}** \n ────────────────── \n Member Count: **${message.guild.memberCount}** \n ────────────────── \n Server ID: **${message.guild.id}** \n ──────────────────`)
.setTimestamp()
.setFooter(`Ran by: ${message.author.username.id}`)
message.channel.send(embed)
For my result, I get "undefiened"
anyone know the solution to this? (.setFooter)
message.author.tag for get the user with tag (JohnDoe#0000)
message.author.user for get the user
message.author.user.username for get the Username
message.author.user.id for get the ID
Simple (:
To get the complete tag of a user, you can just use .tag after message.author.
In your code, you're trying to get the username but you put .id after it so this is why you get "undefined".
The ID isn't the numbers with the hashtag, it's the user ID and the tag is the username plus the numbers with the hashtag.
⠀⠀⠀↱ John Doe#3040 ↰
Username⠀⠀⠀⠀ ⠀⠀Numbers
↳⠀⠀⠀⠀⠀⠀⠀⠀Tag⠀⠀⠀⠀⠀⠀⠀ ↲
So, to get the username and tag, just do this:
//say it’s called msg instead of message
var tag = msg.author.tag;
var username = msg.author.id;
//tag would return the user's tag, and as someone else stated in a comment in a previous answer, author returns a user, which itself doesn't have a user property because it is the user object
Also just a quick tip: since it’s server info command, you might want to put some information about the user that’s exclusive to that guild (nickname, roles, permissions), and for that, you can use msg.member which returns a GuildMember, which has a user property, and many more, like member.displayName and member.roles
if(msg.content.startsWith("&%walcome")){
const mentionid = bot.users.cache.get(`${msg.mentions.users.first().id}`)
const up = new Discord.MessageEmbed()
.setColor('#C8CAF9')
.setTitle('Sup')
.setThumbnail(`${msg.mentions.users.first().displayAvatarURL()}`)
.setDescription(`Sup **${msg.mentions.user.first().tag}**, be welcome to MFPA Official Discord Community. If you joined withouht knowing wth is this server, I will explain: this is the official server of the series with the same new, that is available on youtube (https://www.youtube.com/channel/UCWZRrkidNF5Se8fkgGzoxgg)`)
.addFields(
{name: 'Fun in server', value: 'That is right, dear new member, you can actually have fun in this channel! We have some custom emojis, events, chat (sometimes is dead but eh-). But!, first of all, do not forget to go to #verify (823564914605686844) to get access to the server'},
{name: 'Specific Announcements', value: 'You can receive specific announcements (Faded Pics, Betro Ideas and Dani Sounds) if you are interested in the whole production of the series'},
{name: 'If you need help, just dm a staff member', value: 'Thats right, if you need help, you can contact one of the Staff Team member, they will reply when available'}
)
.setFooter(`Sent by ${msg.author.tag}, bot made by dani bear#3606`, `${msg.author.displayAvatarURL()}`)
mentionid.send(up)
}
})
So, this code is not working, and I don't know why. The error is Cannot read property 'first' of undefined, but I already used this and it worked-
If you could help I would be grateful!
You have a typo in .setDescription('Sup **${msg.mentions.user.first().tag...)}'.Its msg.mentions.users.first()(Missed an 's' in 'users'). Also, if you are going to use the mentioned User object again and again, store then in a variable, and then access the properties of that.
So I've been trying to create a ?members command which lists all the users with a role.
So far I've got this:
if (message.content.startsWith("?members")) {
let roleName = message.content.split(" ").slice(1).join(" ");
let membersWithRole = message.guild.members.filter(member => {
return member.roles.find("name", roleName);
}).map(member => {
return member.user.username;
})
const embed = new Discord.RichEmbed({
"title": `Members in ${roleName}`,
"description": membersWithRole.join("\n"),
"color": 0xFFFF
});
return message.channel.send(embed);
}
So, it works if you type the exact name of the role, but not when you ping it or type the first word. I've been trying for hours to figure out how to do it, and I figured I should ask for help.
Thanks in advance!
Pings get translated into a code as they come through, there is a lot of information on how to parse them in the official guide After it's parsed into a role id you can just use members.roles.get() because that is what they are indexed by.
As for finding a partial name, for that you are going to have to run a function on your find and use String.includes.
return member.roles.find(role => role.name.includes(roleName));
This will also work for find the whole name of course, so it can replace your existing line.
However, this may result in more than one role. This is also true for searching by the entire role name, however, as there are no restrictions on duplicate named roles. For this you may want to invert you design and search through message.guild.roles first for any matching roles, then search for members with the roles found.
So I finally got "ACL" to work, and now im trying to get the "alias" value from the "AROS" table.
I want to make a simple message like logged in as .... (admin, moderator or user).
After some tinkering i got the "alias" value from the code below but I can't shed the feeling ther's an easier way to do this. Any help or advice will be greatly appreciated.
Currently im using:
$logindata = $this->Acl->Aro->findByForeignKey($user['User']['id']);
$parent_id = $logindata['Aro']['parent_id'];
$rankdata = $this->Acl->Aro->find('first', array('recursive' => -1, 'conditions' => array('Aro.id' => $parent_id)));
$rank = $rankdata['Aro']['alias'];
There are two option for you which is simpler than yours..i tried that in my project.
1.Save your aros with the same alias as its parent.And then you can use it simply with one line code.
2.Or you can save its parent alias into users table and then you get this all again almost every part of your site with $auth .