Heres the code It was working when it was running on my pc but now i uploaded it to replit it gives me this error and idk how to fix it
Heres the full error
node:352) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'add' of undefined
at Object.run (/home/runner/PITOOOOOAOAOA/commands/moderation/warn.js:28:15)
at Client. (/home/runner/PITOOOOOAOAOA/index.js:97:13)
const Discord = require("discord.js");
const { MessageEmbed } = require("discord.js");
const { Color } = require("../../config.js");
const db = require('quick.db');
module.exports = {
name: "warn",
aliases: [],
description: "Warnear A un Usurop!",
usage: "Warn <Mention User> | <Reason>",
run: async (client, message, args) => {
//Start
if (!message.member.hasPermission("BAN_MEMBERS"))
return message.channel.send(
`No tienes permiso `
);
let Member =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);
if (!Member) return message.channel.send(`Profavor menciona a Menciona a un usuario `);
let Reason = args.slice(1).join(" ");
client.db.add(`Warnings_${message.guild.id}_${Member.user.id}`,1);
let Warnings = client.db.get(
`Warnings_${message.guild.id}_${Member.user.id}`
);
let embed = new MessageEmbed()
.setColor(Color)
.setTitle(`Miembro Warneado! <a:686209726878449747:891459309987328041> `)
.addField(`Moderador`, `${message.author.tag} (${message.author.id}`)
.addField(`Miembro Warneado!`, `${Member.user.tag} (${Member.user.id})`)
.addField(`Now Member Warnings`, Warnings)
.addField(`Razon`, `${Reason || "No se proporcionó ninguna razón!"}`)
.setFooter(`Requested by ${message.author.username}`)
.setTimestamp();
message.channel.send(embed);
//End
}
};
So i fixed it lol i didnt define the client.db all i had to do is change client.db to db and it worked
let Warnings = db.get(
`Warnings_${message.guild.id}_${Member.user.id}`
);
Related
I am coding a bot with the below command and it throws an error, but i don't know where is the error
i tried my best
const Discord = require("discord.js");
const client = new Discord.Client({
allowedMentions: {
parse: ["roles", "users", "everyone"],
},
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGES
]
});
const config = require("../config.json");
module.exports = {
name: "quar",
run: async (client, message, args) => {
if (!message.member.permissions.has("ADMINISTRATOR")) return;
let role = message.guild.roles.cache.find(role => role.name === "Quarantined" || role.name === "Quarantine")
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = message.content.split(" ").slice(2).join(" ")
if(!reason) reason = "No reason given."
if(!role) return message.channel.send("❌ This server doesn't have a quarantine role!")
if(!member) return message.channel.send("❌ You didn't mention a member!")
if(member.roles.cache.has(role.id)) return message.channel.send(`❌ That user already quarantined!`)
member.roles.add(role)
.then (() => {
const embed = new Discord.MessageEmbed()
.setTitle(`✅ ${member.user.tag} was quarantined!`)
.setColor("RANDOM")
.setTimestamp()
embed.setFooter(`Requested by ${message.author.username}`)
message.channel.send(embed)
member.send(`You were quarantined in \`${message.guild.name}\`. Reason: ${reason} `).catch(error => {
message.channel.send(`❌ Can't send DM to ${member.user.tag}!`);
});
})
}
}
If I have made a mistake, please help me out
Sorry I don't speak English well
Try the below code out, I made notes along the way to explain as well as improved a small bit of code. I assume this is a collection of 2 separate files which is why they are separated. If they aren't 2 separate files, you do not need the top section, just the bottom.
const {
Client,
Intents,
MessageEmbed
} = require("discord.js");
const client = new Client({
allowedMentions: {
parse: ["roles", "users", "everyone"],
},
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES
]
});
const config = require("../config.json");
const {
MessageEmbed,
Permissions
} = require("discord.js");
module.exports = {
name: "quar",
run: async (client, message, args) => {
if (!message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return;
let role = message.guild.roles.cache.find(role => role.name === "Quarantined" || role.name === "Quarantine")
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = message.content.split(" ").slice(2).join(" ")
if (!reason) reason = "No reason given."
if (!role) return message.channel.send("❌ This server doesn't have a quarantine role!")
if (!member) return message.channel.send("❌ You didn't mention a member!")
if (member.roles.cache.has(role.id)) return message.channel.send(`❌ That user already quarantined!`)
member.roles.add(role)
.then(() => {
const embed = new MessageEmbed()
.setTitle(`✅ ${member.user.tag} was quarantined!`)
.setColor("RANDOM")
.setTimestamp()
.setFooter({
text: `Requested by ${message.author.username}`
})
// author and footer are now structured like this
// .setAuthor({
// name: 'Some name',
// icon_url: 'https://i.imgur.com/AfFp7pu.png',
// url: 'https://discord.js.org',
// })
// .setFooter({
// text: 'Some footer text here',
// icon_url: 'https://i.imgur.com/AfFp7pu.png',
// })
message.channel.send({
embeds: [embed]
}) //embeds must be sent as an object and this was the actual line that was causing the error.
member.send(`You were quarantined in \`${message.guild.name}\`. Reason: ${reason} `).catch(() => { // if error is not used, it is not required to be stated
message.channel.send(`❌ Can't send DM to ${member.user.tag}!`);
});
})
}
}
https://pastebin.com/FWYFSdfD
const Discord = require('discord.js')
module.exports = {
name: 'warn',
description: 'warn a member',
async execute(message, args){
edited = message.content.slice(5);
const guildID = message.guild.Discord
const UserId = message.member.Discord
const Reason = args.splice(1).join('')
let User = message.mentions.users.first()
if(message.member.permissions.has('KICK_MEMBERS')){
try{
member = await message.guild.members.find(message.mentions.users.first())
}catch(err){
const warnEmbed = new Discord.MessageEmbed()
.setTitle("**Warn**")
.setColor("#FF0000")
.addField('text', 'value')
.addField("User:", User, true)
.addField("Reason:", Reason, true)
.setThumbnail("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRGagFW_bh2AfgI1BqAis81CXVg37j8_MKtwg&usqp=CAU")
.setTimestamp()
}
try{
User.send(warnEmbed)
message.channel.send(warnEmbed)
}
catch(err){
return(message.reply('You must format the command <#mention> <reason>'))
}
}
else{
message.channel.send('only staff can use this command')
}
}
}
This is the warn code. But when I try to use it, I get an error saying MessageEmbed field values must be non-empty strings. And how many words do I need to write to send this.
const data = suggestedEmbed.embeds[0];
Hi, I'm having this error and I don't know why it is saying that the code above is the problem. Any solutions for this problem? Thank you for reading.
Code:
module.exports = {
category: "Utility",
description: "Accept valid suggestions!",
expectedArgs: "<messageID> <Reason>",
minArgs: 2,
guildOnly: true,
ownerOnly: true,
callback: ({message, args}) => {
const messageID = args[0]
const acceptQuery = args.slice(1).join(" ");
try{
const suggestionChannel = message.guild.channels.cache.get('834459599699443782');
const suggestedEmbed = suggestionChannel.messages.fetch(messageID);
console.log(suggestedEmbed)
const data = suggestedEmbed.embeds[0];
const acceptEmbed = new Discord.MessageEmbed()
.setAuthor(data.author.name, data.author.iconURL())
.setColor('GREEN')
.setDescription(data.description)
.addField("📊 Status ✅ Accepted! Expect this coming soon!", acceptQuery);
suggestedEmbed.edit(acceptEmbed);
const user = client.users.cache.find((u) => u.tag === data.author.name);
user.send("Your suggestion has been accepted! Thank you for this suggestion, expect this coming soon!")
} catch(err) {
console.log(err)
}
}
}
I've been making a suggestion command and I don't know what the current problem is, please help.
module.exports = {
name: 'suggestions',
aliases: ['suggest', 'suggestion'],
permissions: [],
description: 'creates a suggestions!',
execute(message, args, cmd, client, discord){
const channel = message.guild.channels.cache.find(c => c.name === 'suggestions');
if(!channel) return message.channel.send('suggestions channel does not exist!');
}
}
Here's the error message:
TypeError: Cannot read property 'channels' of undefined
at Object.execute (C:\Users\MyName\Desktop\DiscordBots\commands\suggestions.js:7:39)
Here's my main file:
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"]});
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
client.login('MYTOKEN');
Here's where I run execute() i think:
module.exports = (Discord, client, message) => {
const prefix = '-';
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(command) command.execute(client, message, args, Discord);
}
Please try to define channel and then send message
client.channels.cache.get("CHANNELID").send(`TEST`);
this may be work;
module.exports = {
name: 'suggestions',
aliases: ['suggest', 'suggestion'],
permissions: [],
description: 'creates a suggestions!',
execute(client, message, args, Discord){ // CHANGED
const channel = message.guild.channels.cache.find(c => c.name === 'suggestions');
if(!channel) return message.channel.send('suggestions channel does not exist!');
}
}
Hello guys i try to do command "warns" and i can't fix error can you help me please?
I know the problem is in "if(data.content.length)" and if i remove ".content.length" and use command the bot says "User has not warns" but i have.
Code:
const db = require('../warns')
const { Message, MessageEmbed } = require('discord.js')
module.exports.run = async (_client, message, args) => {
if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('You don\'t have permissions to.')
const user = message.mentions.members.first() || message.guild.members.cache.get(args[0])
if(!user) return message.channel.send('User not found.')
const reason = args.slice(1).join(" ")
db.findOne({ guildid: message.guildid, user: user.user.id}, async(err, data) => {
if(err) throw err;
if(data.content.length){
var warny = new MessageEmbed()
.setTitle(`${user.user.tag} warns`)
.setDescription(
data.content.map(
(w, i) =>
`${i + 1}. | Moderator: ${message.guild.members.cache.get(w.moderator).user.tag}\nReason: ${w.reason}`
))
.setColor('RANDOM')
message.channel.send(warny)
} else {
message.channel.send('User has not warns')
}
})
}
module.exports.help = {
name: 'warns'
}
Error:
(node:5564) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'content' of null
at C:\Users\cyber\Desktop\CzikiBot\commands\warns.js:11:17