how to use the set nickname article? - discord.js

I am trying to make my discord bot change the nickname of a user when they send !name Travis_c
here is my code
case 'name':
message.author.setNickname(args[1], 'Account setup')
break;
I think I'm doing it right, but it keeps saying .setnickname is not a function. if I'm not using it right, how do I use it?

You are trying to use .setNickname() on the User which won't work since only GuildMember has the nickname property and the setNickname() method
case 'name':
message.member.setNickname(args[1], 'Account setup')
break;

Related

How do I get someones username AND tag? (Discord.js)

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

Trying to do a dm command with msg.mentions.users.first, but it's not working

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.

Add MEMBER to username when joined

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);
});

Is it possible to send multiple RichEmbeds in a single message

In the documentation, it states that a Message can have an array of Embeds.
This obviously makes one question if it's possible to send multiple RichEmbed with a single message.
The normal way to send an Embed is to use a MessageOptions Object, like this:
message.channel.send({embed: embedName});
Although this doesn't seem to allow for a multiple of RichEmbeds, does anyone know if it's possible to send multiple?
As Abz6is pointed out, you can post multiple RichEmbeds at once by using a Webhook.
Here is the documentation for the WebhookMessageOptions.
Quick example:
message.channel.createWebhook('Webhook Name', message.author.displayAvatarURL)
.then(w => w.send({embeds: [
new Discord.RichEmbed().setAuthor('Embed 1'),
new Discord.RichEmbed().setAuthor('Embed 2'),
]}));
This works for up to 10 embeds.
Yes! it is Possible to do this, by doing
if(message.content.startswith(Anything)) {
message.channel.send({embed: embedName});
message.channel.send({embed: embedName});
}
Caltrop's Answer also Works.

Can we use "include?" in this situation?

I just want to know whether i can use include? method in this place or not, Is it appropriate to use include method here?
I have a Users table and a Roles table, there are many_to_many relation in b/w user & role.
Now i want to check the role of the user.
something like this:
1. Using include
This is returning false whereas i am expecting true, coz that user having admin role.
def isadmin(user)
user.roles.include?("admin")
end
2. Without include
This solution is working for me but i want to know about include.
def isadmin(user)
for role in user.roles
if role.name == "admin"
return true
end
end
false
end
Note: I have this role assigned to the user for whom i am checking the role.
#<Role id: 1, name: "admin", created_at: "2014-12-07 07:45:42", updated_at: "2014-12-07 07:45:42">
The first one isn't working because you're comparing an array of role objects to a string. You want something like this:
user.roles.map(&:name).include?('admin')

Resources