I'm writing a discord bot using the discord.js
v12.2.0 library and I get this error:
Waiting for the dTypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received undefined
This is my code:
const { MessageEmbed } = require("discord.js");
const { VultrexDB } = require("vultrex.db");
const messageData = new VultrexDB({
name: "messages"
})
module.exports.run = (client, message, args) => {
const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member;
const messages = messageData.get(`${message.guild.id}-${member.id}`, 0);
message.chanel.send(new MessageEmbed()
.setColor("E67E22")
.setAuthor(`Data | ${member.user.username}`, member.user.displayAvatarURL())
.addField("Messages Sent:", messages, true)
);
}
module.exports.help = {
name: "messages",
description: "view the amount of messages sent by a member"
}
module.exports.requirements = {
clientPerms: ["EMBED_LINKS"],
userPerms: [],
ownerOnly: false
}
You should learn to debug especially since this error practically tells you the answer. Did it tell you which line? If so there;s your answer but incase it didnt:
new VultrexDB
, message.mentions.members.first
, message.mentions.members.cache.get
, messageData.get
, new MessageEmbed
, setColor
, setAuthor
, addField
you can rule out MessageEmbed and
message.mentions.members.first since they don't require any arguments,
setColor ,
setAuthor , and
addField` all are giving arguments
that leaves new VultrexDB
, message.mentions.members.cache.get
and messageData.get
for message.mentions.members.cache.get
, it only requires one argument, the id, and you pass it by args[0]
, so to check if this is the problem just check if you have args
for new VultrexDB
and messageData.get
, those are VultrexDB based and idk it, so just look at a guide or the documentation if they have one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.