I need a AutoRole command discord.js when somebody join my discord server he gets the Discord Member role.
Ive tryied some code but it doesnt work.
const discord = require("discord.js");
const config = require('../config.json');
module.exports.run = async (bot, message, args) => {
let target = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
let reason = args.slice(1).join(' ');
let logs = message.guild.channels.find('name', config.logsChannel);
if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you do not have permissions to use this command!s');
if (!target) return message.reply('please specify a member to ban!');
if (!reason) return message.reply('please specify a reason for this ban!');
if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`);
let embed = new discord.RichEmbed()
.setColor('RANDOM')
.setThumbnail(target.user.avatarURL)
.addField('Banned Member', `${target.user.username} with an ID: ${target.user.id}`)
.addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`)
.addField('Banned Time', message.createdAt)
.addField('Banned At', message.channel)
.addField('Banned Reason', reason)
.setFooter('Banned user information', target.user.displayAvatarURL);
message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`);
target.ban(reason);
logs.send(embed);
};
module.exports.help = {
name: 'ban'
};
When they join they get the Discord Member role.
You can use the guildMemberAdd event to do actions on new users.
client.on("guildMemberAdd", (member) => {
member.addRole('ROLE ID HERE')
});
Related
const Discord = require('discord.js');
module.exports = {
name: 'unban',
aliases: ['uban', 'unban'],
category: 'misc',
permissions: ['BAN_MEMBERS'],
description:
'Use this command to permanately or temporary ban a server member from Sekai.',
/**
* #param {Discord.Message} message
* #param {Array} args
*/
async execute(message, args) {
if (message.mentions.users.size === 0)
return message.reply('Please mention a user to unban ❌');
const targetid = message.mentions.users.first().id;
if (targetid === message.client.user.id)
return message.reply(
"Me? Really? That's not very nice, I guess you failed 🤡"
);
const targed = await message.guild.members.cache.get(targetid);
let reason = [];
if (args.length >= 2) {
args.shift();
reason = args.join(' ');
} else reason = 'No Reason provided';
try {
let extra = '';
try {
const embed = new Discord.MessageEmbed()
.setTitle('Moderation message regarding on your **BAN**')
.setAuthor("Joony's Den")
.setDescription(
`you have been banned from **${message.guild.name} ✅ **\nReason for ban: **${reason}\n${extra}**`
)
.addField('Contact','If you believe that your ban was unjustified, please feel free to contact any of these staff members. **JOONY#9513** or any of administrators online.')
.setColor('#2243e6')
.addField('Appeal Accepted?','if your appeal was accepted, please join using this link. your link will expire after 1 use. **https://discord.gg/4yuCzUC7aw**')
.addField(
'Appeal',
'Because you have been banned from the server, you will have one chance to appeal 🔨. Your appeal will be processed to the administrators or appeal managers ✅ **[CLICK HERE TO APPEAL](https://forms.gle/atc75ZftpdfJhfH56)**'
);
targed.send(embed);
} catch (error) {
extra = 'Messaging the user has failed! ❌';
}
setTimeout(() => {
targed.unban(targed, [reason])
const embed = new Discord.MessageEmbed()
.setTitle('User unbanned')
.setDescription(
`${
targed.tag || targed.user.username
} has been sucessfully unbanned from **${
message.guild.name
} ✅ **\nReason for unban: **${reason}\n${extra}**`
)
.setColor('#FA2657');
message.channel.send(embed);
}, 2000);
} catch (error) {
message.channel.send(
`I could not unban the given member, make sure that my role is above member! ❌`
);
}
},
};
Hello! how do I unban the user using this format, it has an error saying "guild.unban is undefined"
it has an error saying
targed.unban([reason])
^
TypeError: targed.unban is not a function
at Timeout._onTimeout (C:\Users\Joon\Documents\GitHub\Discord-Bot\commands\misc\unban.js:49:16)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
You cannot unban a GuildMember (a banned user is not a member of a Guild). You should call unban on GuildMemberManager. See https://discord.js.org/#/docs/main/stable/class/GuildMemberManager?scrollTo=unban
i am tring to do that every time someone that joins my server blocks dms the bot will open a channel and send a verify link instead of a dm
what I stuck on (store the channel and stuff like that)
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {message.guild.channels .create(member.id, { type: "text" }), channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
what I had
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
To create the channel you can just use GuildChannelManager#create (aka guild.channels.create).
member.guild.channels.create(`${member.author.username}-verification`, {
permissionOverwrites: [
{
id: member.author.id,
allow: ['VIEW_CHANNEL'],
},
{
id: member.guild.id,
deny: ['VIEW_CHANNEL'],
},
]
});
To send a message to the channel there are two ways you can do it.
A: Store the channel object.
const verifyChannel = member.guild.channels.create(`channel`);
verifyChannel.send('Message!')
B: Use .then() as creating as channel returns a promise.
member.guild.channels.create(`channel`)
.then(chan => {
chan.send('Message!');
});
I am making a discord bot using discord.js, and what I want to do is to have the bot find members with Roles A and B, and list them in an embedded message. Currently, I have:
else if (message.content === (!'guns') && message.channel.id == '732740415056380044') {
let team = message.guild.roles.find('name', 'WindStar Team');
let awper = message.guild.roles.find('name', 'AWPer');
let rifler = message.guild.roles.find('name', 'Rifler');
const Members1 = awper = awper.filter(val => !team.includes(val)).map(member => member.displayName);
const Members2 = rifler = rifler.filter(val => !team.includes(val)).map(member => member.displayName);
const embedmesage = new Discord.MessageEmbed()
.setTitle('Preferred Guns')
.setColor(0x00AE86)
.addFields(
{ name: 'AWPers', value: `${Members1.join('\n')}` },
{ name: 'Riflers', value: `${Members2.join('\n')}` },
);
message.channel.send(embedmesage);
return console.log('Preferred gun roles command for windstar team executed');
}
Basically, I am trying to cross-check members who have the WindStar Team role and AWPer role, and send the list of all members who have those roles into an embed. I am also trying to cross-check members with the WindStar Team role and the Rifler role, and send the list of those members into an embed.
let awper = message.guild.roles.find('name', 'AWPer');
awper.members //Either .toArray() or .map(m => m.displayName)
I think, I dont have my bot in front of me to test
I think it is maybe too late at this point but I'll give my solution anyway. (using discord.js v12.5.1)
<Message> = your message instance
let roleMembers = <Message>.guild.roles.cache.filter(role => role.name === "AwPer" && role.name === "WindStar").members
// displaying the role members
roleMembers.map(member => member.user.username)
Basically you are getting all the roles in a guild a cache and filtering them to display the roles you want.
This should work ^. Unless you are using a breaking version of discord.js
I have this command on my bot where you can mute someone using the command g!mute where the 'user' is mentioned using #. However, if you don't mention e.g GeoGeo instead of #GeoGeo, it causes the bot to crash. I know you need to put .catch(console.error); somewhere, but I'm not sure where. Thanks in advance. The Error is
let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
^
TypeError: message.guild.members.get is not a function
Code:
const Discord = require('discord.js');
const ms = require('ms');
module.exports = {
name: 'mute',
description: "this is mute command",
execute(message, args){
if(!message.member.roles.cache.find(r => r.name ==="Staff", "Head Staff", "Owner", "Co-Owner")) return message.channel.send(`YOU DO NOT HAVE PERMISSION TO DO THAT`)
let members = args[0];
if(!members) return message.reply("g!mute <user> <time>")
let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
if(!person) return message.reply("That person is not in the server!");
let mainrole = message.guild.roles.cache.find(role => role.name === "Fans");
let muterole = message.guild.roles.cache.find(role => role.name === "muted");
if(!muterole) return message.reply("That role does not exist");
let time = args[1];
if(!time){
return message.reply("g!mute <user> <time>");
}
person.roles.remove(mainrole.id);
person.roles.add(muterole.id);
const embed = new Discord.MessageEmbed()
.setTitle ("Muted:")
.setDescription (`${person.user.tag} has now been muted for ${ms(ms(time))}`)
.setColor(0x01B8FF)
message.channel.send(embed);
setTimeout(function(){
person.roles.add(mainrole.id)
person.roles.remove(muterole.id)
const embed = new Discord.MessageEmbed()
.setTitle ("Muted:")
.setDescription (`${person.user.tag} has been unmuted`)
.setColor(0x01B8FF)
message.channel.send(embed);
}, ms(time));
}
}
When faced with an error like: TypeError: message.guild.members.get is not a function
The logical thing to do is check the docs to see that message.guild.members really has a function named get. Here's the docs: https://discord.js.org/#docs/main/stable/class/GuildMemberManager
No get. But there is a cache like you use elsewhere in the code. Just by checking over the docs you can tell that your existing code is wrong (it's outdated) and you need to use cache like you do elsewhere in your code:
message.guild.members.cache.get(args[1])
I want to write code that will check if the roles are in the list. If yes, then they can be issued, and if not, then no. I'm new in discord js.
if(!rMember.roles.has((['00000000000000', '00000000000000, '00000000000000', '00000000000000', '00000000000000']))) return message.reply("nope.");
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
if(!message.member.hasPermission("MANAGE_MEMBERS")) return message.reply();
let rMember = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
if(!rMember) return message.reply("I can't find player.");
let role = args.join(" ").slice(22);
if(!role) return message.reply("specify rang!");
let gRole = message.guild.roles.find(`name`, role);
if(!gRole) return message.reply("I can't find this rang!.");
if(rMember.roles.has(gRole.id)) return message.reply("I can't do it.");
if(!rMember.roles.has((['00000000000000', '00000000000000, '00000000000000', '00000000000000', '00000000000000']))) return message.reply("nope.");
await(rMember.removeRoles(['00000000000000', '00000000000000, '00000000000000', '00000000000000', '00000000000000']));
await(rMember.addRole(gRole.id));
try{
await rMember.send(`Your rang was changed to ${gRole.name}!`)
}catch(e){
}
}
module.exports.help = {
name: "role"
}
It works without check code, but if I add it, all times, when I will try to change role of user, it gives out "nope".
You could check whether the given role is in the list of allowed roles using Array.includes().
const allowed = ['id', 'anotherID', 'andAnother'];
if (!allowed.includes(gRole.id)) return;
// Returns if the role is *not* in the 'allowed' array.