I dont know why I am getting this error this is my code.
Can anyone help me with this please? That would be nice.
const discord = require("discord.js");
const moment = require("moment");
module.exports.run = async(bot, message, args) => {
var member = message.guild.member(message.mentions.users.first() || client.users.cache.get(args[0]));
if(!member) member = message.member;
var roles = member.roles.cache.size - 1;
var roleNames = member.roles.cache.map(r => r).join(" ").replace("#everyone", "");
if(roles == 0) roleNames = "Geen rollen";
var status = member.presence.status;
var nickName = member.nickname;
if(nickName == null || undefined) nickName = "Geen";
var embed = new discord.MessageEmbed()
.setColor("#00ff00")
.setThumbnail(member.user.displayAvatarURL({size: 4096}))
.setTitle(`${member.user.tag}`)
.addField("ID:", `${member.id}`, true)
.addField("Bijnaam:", nickName, true)
.addField("Status:", `${status}`, true)
.addField("Game", `${member.presence.activities[0] ? member.presence.activities[0].name : 'Geen'}`, true)
.addField("Account gemaakt", `${moment(member.user.createdAt).format("LL")}`)
.addField(`Rollen [ ${roles}]`, `${roleNames}`);
message.channel.send(embed);
}
module.exports.help = {
name: "userinfo"
}
The problem is on line 6 and here's that code on line 6
var member = message.guild.member(message.mentions.users.first() || client.users.cache.get(args[0]));
I assume you passed in client as "bot". Just replace client with bot.
Related
static description = 'Get information on a mentioned user.';
static usage = '<#user|id>';
static names = ['userinfo', 'ui'];
static userPerms = [];
static botPerms = [];
async execute(client, message) {
var permissions = [];
var acknowledgements = 'None';
const args = this.message.content.trim().split(/ +/g);
var user = this.message.mentions.users.first() || this.message.author;
const member = this.message.mentions.members.first() || this.message.guild.members.cache.get(args[0]) || this.message.member;
const randomColor = "#000000".replace(/0/g, function () { return (~~(Math.random() * 16)).toString(16); });
if(this.message.member.hasPermission("KICK_MEMBERS")){
permissions.push("Kick Members");
}
if(this.message.member.hasPermission("BAN_MEMBERS")){
permissions.push("Ban Members");
}
if(this.message.member.hasPermission("ADMINISTRATOR")){
permissions.push("Administrator");
}
if(this.message.member.hasPermission("MANAGE_MESSAGES")){
permissions.push("Manage Messages");
}
if(this.message.member.hasPermission("MANAGE_CHANNELS")){
permissions.push("Manage Channels");
}
if(this.message.member.hasPermission("MENTION_EVERYONE")){
permissions.push("Mention Everyone");
}
if(this.message.member.hasPermission("MANAGE_NICKNAMES")){
permissions.push("Manage Nicknames");
}
if(this.message.member.hasPermission("MANAGE_ROLES")){
permissions.push("Manage Roles");
}
if(this.message.member.hasPermission("MANAGE_WEBHOOKS")){
permissions.push("Manage Webhooks");
}
if(this.message.member.hasPermission("MANAGE_EMOJIS")){
permissions.push("Manage Emojis");
}
if(!permissions.length == 0){
permissions.push("No Key Permissions Found");
}
if(this.member.user.id == message.guild.ownerID){
acknowledgements = 'Server Owner';
}
const embed = new Discord.MessageEmbed()
.setDescription(`<#${member.user.id}>`)
.setAuthor(`${member.user.tag}`, member.user.displayAvatarURL)
.setColor(randomColor)
.setFooter(`ID: ${message.author.id}`)
.setThumbnail(member.user.displayAvatarURL)
.setTimestamp()
.addField("Status",`${status[member.user.presence.status]}`, true)
.addField('Joined at: ',`${moment(member.joinedAt).format("dddd, MMMM Do YYYY, HH:mm:ss")}`, true)
.addField("Created at: ",`${moment(message.author.createdAt).format("dddd, MMMM Do YYYY, HH:mm:ss")}`, true)
.addField("Permissions: ", `${permissions.join(', ')}`, true)
.addField(`Roles [${member.roles.cache.filter(r => r.id !== message.guild.id).map(roles => `\`${roles.name}\``).length}]`,`${member.roles.cache.filter(r => r.id !== message.guild.id).map(roles => `<#&${roles.id }>`).join(" **|** ") || "No Roles"}`, true)
.addField("Acknowledgements: ", `${acknowledgements}`, true);
this.message.channel.send({embed});
}
}
**I have tried to define user but it's not working. error:
TypeError: Cannot read property 'user' of undefined.
Whenever i used ,userinfo it's not responding anything. I don't know why this happend, but if you find any other error in the code, can you help me fix it too? Thank you.
but that didn't do anything to help.
What am i missing here?**
this.member.user.id
Should be
member.user.id
Look for “something”.user for errors like that. Then figure out why the something is undefined.
My Problem is that my bot tells me when i hit the reaction of the embed message that name is undefied. I don´t know how to fix this or how i should define name. I also dont know if this code, the reactionMemberAdd part works for many roles. It would be very great if one can help me
const Discord = require("discord.js")
const fs = require("fs")
const generalrolesConfig = JSON.parse(fs.readFileSync('./configs/generalroles.json', 'utf-8'))
module.exports = client => {
//Allgemein
//Chat Nachricht um Embed aufzurufen: general :space_invader: 813828905081110568 :computer: 815181805350682655 :frame_photo: 815181807234449428
//id von member:813828905081110568 👾
//id von programmierer: 815181805350682655 💻
//id von grafiker/desginer: 815181807234449428 🖼
client.on('message', async (msg) => {
if(msg.author.bot || !msg.guild) return;
if(msg.content.startsWith('!general')) {
var args = msg.content.split(' ')
if(args.length == 7) {
var emoji1 = args[1]
var roleid1 = args[2]
var emoji2 = args[3]
var roleid2 = args[4]
var emoji3 = args[5]
var roleid3 = args[6]
var role = msg.guild.roles.cache.get((roleid1 || roleid2 || roleid3))
if(!role) {
msg.reply('Die Rolle gibt es nicht'); return
}
var generalembed = new Discord.MessageEmbed()
.setTitle("Allgemein")
.setColor("RED")
.setDescription('TEST')
var sendedMessage = await msg.channel.send(generalembed)
sendedMessage.react(emoji1).then(sendedMessage.react(emoji2)).then(sendedMessage.react(emoji3))
var toSave = {message: sendedMessage.id, emoji1: emoji1, roleid1: roleid1, emoji2: emoji2, roleid2: roleid2, emoji3: emoji3, roleid3: roleid3}
generalrolesConfig.reactions.push(toSave)
fs.writeFileSync('./configs/generalroles.json', JSON.stringify(generalrolesConfig))
} else {
msg.reply('etwas ist falsch gelaufen')
}
}
})
client.on('messageReactionAdd', (reaction, user) => {
if(reaction.message.partial) reaction.fetch()
if(reaction.partial) reaction.fetch()
if(user.bot || !reaction.message.guild) return
for (let index = 0; index < generalrolesConfig.reactions.length; index++) {
let reactionRole = generalrolesConfig.reactions[index]
if(reaction.message.id == reactionRole.message && reaction.emoji1.name == reactionRole.emoji1 && !reaction.message.guild.members.cache.get(user.id).roles.cache.has(reactionRole.roleid)) {
reaction.message.guild.members.cache.get(user.id).roles.add(reactionRole.role)
}
}
})
}
Here is my entire code for my ban command. Good to note I am using Discord.JS Commando as well I have been struggling with this error but literally cannot figure out why I am getting it everything looks fine unless I have used a deprecated function. Would really appreciate someone to help me on this one I've been getting along quite well creating a rich featured bot before this happened.
const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const db = require('quick.db');
module.exports = class banCommand extends Command {
constructor(client) {
super(client, {
name: 'ban',
memberName: "ban",
group: 'moderation',
guildOnly: true,
userPermissions: ['BAN_MEMBERS'],
description: 'Bans the mentioned user from the server with additional modlog info.'
});
}
async run(message, args) {
if (!args[0]) return message.channel.send('**Please Provide A User To Ban!**')
let banMember = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.guild.members.cache.find(r => r.user.username.toLowerCase() === args[0].toLocaleLowerCase()) || message.guild.members.cache.find(ro => ro.displayName.toLowerCase() === args[0].toLocaleLowerCase());
if (!banMember) return message.channel.send('**User Is Not In The Guild**');
if (banMember === message.member) return message.channel.send('**You Cannot Ban Yourself**')
var reason = args.slice(1).join(' ');
if (!banMember.bannable) return message.channel.send('**Cant Kick That User**')
banMember.send(`**Hello, You Have Been Banned From ${message.guild.name} for - ${reason || 'No Reason'}**`).then(() =>
message.guild.members.ban(banMember, { days: 7, reason: reason })).catch(() => null)
message.guild.members.ban(banMember, { days: 7, reason: reason })
if (reason) {
var sembed = new MessageEmbed()
.setColor('GREEN')
.setAuthor(message.guild.name, message.guild.iconURL())
.setDescription(`**${banMember.user.username}** has been banned for ${reason}`)
message.channel.send(sembed)
} else {
var sembed2 = new MessageEmbed()
.setColor('GREEN')
.setAuthor(message.guild.name, message.guild.iconURL())
.setDescription(`**${banMember.user.username}** has been banned`)
message.channel.send(sembed2)
}
let channel = db.fetch(`modlog_${message.guild.id}`)
if (channel == null) return;
if (!channel) return;
const embed = new MessageEmbed()
.setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL())
.setColor('#ff0000')
.setThumbnail(banMember.user.displayAvatarURL({ dynamic: true }))
.setFooter(message.guild.name, message.guild.iconURL())
.addField('**Moderation**', 'ban')
.addField('**Banned**', banMember.user.username)
.addField('**ID**', `${banMember.id}`)
.addField('**Banned By**', message.author.username)
.addField('**Reason**', `${reason || '**No Reason**'}`)
.addField('**Date**', message.createdAt.toLocaleString())
.setTimestamp();
var sChannel = message.guild.channels.cache.get(channel)
if (!sChannel) return;
sChannel.send(embed)
}
};
The reason you are getting the TypeError: args.slice(...).join is not a function error is because the slice method creates a new array of the sliced data, and so can not join(' ') since there is no space to join with. (i.e. it is not a string)
What you are looking for is args.slice(1).toString().replace(",", " ")
This removes the 2nd part of the args array object, then converts it to a string, then removes the commas in the string and replaces them with spaces.
Hello Stackoverflow community. I'm quite curious, regarding the channelUpdate event in Discord.js, is it possible to ignore some channels but log the rest?
bot.on("channelUpdate", async (oldChannel, newChannel) => {
// Get stat channel IDs
let totalUsers = oldChannel.guild.channels.get('667335552558956554');
let onlineUsers = oldChannel.guild.channels.get('667335645894541331');
let totalBots = oldChannel.guild.channels.get('667337560179343374');
//Leave the stat channels alone, or too much logging will happen
//.parent.id === '667335310350352394';
if (totalUsers || onlineUsers || totalBots) return;
let oldCategory = oldChannel.parent;
let newCategory = newChannel.parent;
let guildsChannel = newChannel.guild;
if (!newCategory) newCategory = "None";
if (!guildsChannel || !guildsChannel.available) return;
let types = {
"text" : "Text channel",
"voice" : "Voice channel",
"null" : "None"
};
const logchannel = channel.guild.channels.find(channel => channel.name === "server-logs")
if (!logchannel) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;
if (oldChannel.name !== newChannel.name) {
let channelNameUpdateEmbed = new Discord.RichEmbed()
.setColor("#ffc500")
.setDescription("Channel name updated.")
.addField("Old channel name", `\`${oldChannel.name}\``, true)
.addBlankField(true)
.addField("New channel name", `\`${newChannel.name}\``, true)
.addField("Channel type", `${types[newChannel.type]}`, true)
.addBlankField(true)
.addField("Channel category", `${newCategory}`, true)
.setFooter(`Channel ID: ${newChannel.id} 🔥`)
.setTimestamp()
logchannel.send(channelNameUpdateEmbed).catch()
}
});
Those marked as so called "Stat channels", is it possible to ignore those? Else log channels will get flooded every time a member goes online or offline
Thanks in advance!
Sure, you can create ingoreChannel arr and check if channel in ignore arr.
Like this:
bot.on('channelUpdate', async (oldChannel, newChannel) => {
const ignoreChannels = ['667335552558956554', '667335645894541331', '667337560179343374'];
// Get stat channel IDs
if (ignoreChannels.includes(oldChannel.id)) return;
//Leave the stat channels alone, or too much logging will happen
//.parent.id === '667335310350352394';
let oldCategory = oldChannel.parent;
let newCategory = newChannel.parent;
let guildsChannel = newChannel.guild;
if (!newCategory) newCategory = 'None';
if (!guildsChannel || !guildsChannel.available) return;
let types = {
text: 'Text channel',
voice: 'Voice channel',
null: 'None',
};
const logchannel = channel.guild.channels.find(channel => channel.name === 'server-logs');
if (!logchannel) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;
if (oldChannel.name !== newChannel.name) {
let channelNameUpdateEmbed = new Discord.RichEmbed()
.setColor('#ffc500')
.setDescription('Channel name updated.')
.addField('Old channel name', `\`${oldChannel.name}\``, true)
.addBlankField(true)
.addField('New channel name', `\`${newChannel.name}\``, true)
.addField('Channel type', `${types[newChannel.type]}`, true)
.addBlankField(true)
.addField('Channel category', `${newCategory}`, true)
.setFooter(`Channel ID: ${newChannel.id} 🔥`)
.setTimestamp();
logchannel.send(channelNameUpdateEmbed).catch();
}
});
My bot returns undefined when using bot.channels.get(channelid).
Here's a sample of my code:
//this is executed in a guild with id 416809320513011713
const Discordjs = require("discord.js");
const bot = new Discordjs.Client();
const auth = require('./auth.json');
const FileSys = require("fs");
bot.on('messageDelete', async function (message) {
console.log('message deleted')
let currentguildsettings = JSON.parse(FileSys.readFileSync('./DatStore/GuildDat/' + message.guild.id + '.dat', 'UTF8'));
if (currentguildsettings[0] == 1) {
if (currentguildsettings[1] != 0) {
let channelid = currentguildsettings[1].toString()
let channel = bot.channels.get(channelid);
console.log('settings on true, channelid ' + channelid)
if (channel) {
console.log('channel found')
}
}
}
}
bot.login(auth.token)
file ./DatStore/GuildDat/416809320513011713.dat contains:
[1,424085503361417200,0]
Here's the output:
message deleted
settings on true, channelid 424085503361417200
If the channel was found it should've logged 'channel found' in the output.
What should I change to make it return the channel?
The channel id key is a string, you must enclose it as a string in your array.
let c1 = bot.channels.get(424085503361417200); // Will produce undefined
let c2 = bot.channels.get('424085503361417200'); // Will produce a channel object (if available)
The channel wasn't available since I used the wrong id:
I saved the id's at my server settings command in int format instead of string, parseInt() broke the exact number.
if (logchannelaction == 'set') {
if (currentguildsettings[1] == message.channel.id) return message.reply("logchannel was already set to this channel");
currentguildsettings[1] = parseInt(message.channel.id);
message.reply("logchannel has set to #" + message.channel.name);
if (currentguildsettings[0] == 0) {
currentguildsettings[0] = 1
message.reply("logchannel has automatically enabled");
}
FileSys.writeFileSync(guilddatpath, JSON.stringify(currentguildsettings));
return
}
Thank you for trying to help me.