I am making a report/bug command and got this error:
reportschannel is undefined
Here is my full code:
switch (args[0]) {
case "report":
message.delete({ timeout: 3000 });
let target =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);
if (!target)
return message.channel
.send("Please provide a user that you wish to report")
.then((m) => m.delete({ timeout: 15000 }));
if ((args[1] === target, args[2] === reason)) {
message.channel.send(
"Your report has been filled to the staff team. Thank you for reporting!"
);
reportsChannel.send(
`**${message.author.username}** has reported **${target.user.username}** for **${reason}**.`
);
}
var reason = args.slice(2).join(" ");
if (!reason)
return message.channel
.send(
`Please provide a reason for reporting **${target.user.username}**`
)
.then((m) => m.delete({ timeout: 15000 }));
let reportsChannel = message.guild.channels.cache.find(
(x) => x.name === "wide log"
);
break;
}
I'm not quite sure what's going wrong in my code; am I overlooking something? Thanks in advance.
Variable must be above where you use it. For example:
let reportsChannel = message.guild.channels.cache.find(x => x.name === "wide log")
reportsChannel.send(...)
By the way, Discord channel names cannot contain space. Use wide-log
instead of wide log
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.