command not respoding

const { EmbedBuilder } = require("discord.js");
const { getMember } = require("../../util");
const util = require('../../util');
const config = require(`${process.cwd()}/config.js`);

module.exports = {
name: "testdm",
async run (client, message, args) {
if (!message.member.roles.cache.has(config.moderation.modRole)) return message.delete();
else if (message.channel.id !== config.channels.staffCommands) return message.delete();
const arg = args[0]
const user = await util.getMember(message.guild, arg)

const errEmbed = new EmbedBuilder()
.setDescription(`Provide a user.`)
.setColor(config.colors.red)

const errEmbed2 = new EmbedBuilder()
.setDescription(`Provide a valid user.`)
.setColor(config.colors.red)

if (!arg) {
message.channel.send({ embeds: [errEmbed] }).then(a => {
setTimeout(() => { message.delete(), a.delete() }, 3000)
})
} else if (user === undefined) {
message.channel.send({ embeds: [errEmbed2] }).then(a => {
setTimeout(() => { message.delete(), a.delete() }, 3000)
})

const dmEmbed = new EmbedBuilder()
.setTitle(`test`)
.setDescription(`test`)

const embed = new EmbedBuilder()
.setDescription(`DM sent to ${user}.`)
.setColor(config.colors.green)

user.send({ embeds: [dmEmbed] })
message.channel.send({ embeds: [embed] })
}}
}
const { EmbedBuilder } = require("discord.js");
const { getMember } = require("../../util");
const util = require('../../util');
const config = require(`${process.cwd()}/config.js`);

module.exports = {
name: "testdm",
async run (client, message, args) {
if (!message.member.roles.cache.has(config.moderation.modRole)) return message.delete();
else if (message.channel.id !== config.channels.staffCommands) return message.delete();
const arg = args[0]
const user = await util.getMember(message.guild, arg)

const errEmbed = new EmbedBuilder()
.setDescription(`Provide a user.`)
.setColor(config.colors.red)

const errEmbed2 = new EmbedBuilder()
.setDescription(`Provide a valid user.`)
.setColor(config.colors.red)

if (!arg) {
message.channel.send({ embeds: [errEmbed] }).then(a => {
setTimeout(() => { message.delete(), a.delete() }, 3000)
})
} else if (user === undefined) {
message.channel.send({ embeds: [errEmbed2] }).then(a => {
setTimeout(() => { message.delete(), a.delete() }, 3000)
})

const dmEmbed = new EmbedBuilder()
.setTitle(`test`)
.setDescription(`test`)

const embed = new EmbedBuilder()
.setDescription(`DM sent to ${user}.`)
.setColor(config.colors.green)

user.send({ embeds: [dmEmbed] })
message.channel.send({ embeds: [embed] })
}}
}
23 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
-Carlosđź‘‘
-Carlos👑OP•2y ago
it only reponds to the if (!arg)
MrMythical
MrMythical•2y ago
You should use slash commands But what exactly is the problem?
-Carlosđź‘‘
-Carlos👑OP•2y ago
command not responding, it only responds when I don't provide an arg ( if(!arg) )
MrMythical
MrMythical•2y ago
then what is user
-Carlosđź‘‘
-Carlos👑OP•2y ago
I provided an mention
MrMythical
MrMythical•2y ago
hold on
-Carlosđź‘‘
-Carlos👑OP•2y ago
the await util.getMember(message.guild, arg) is made so it detects ids and mentions
MrMythical
MrMythical•2y ago
let me see the command handler
-Carlosđź‘‘
-Carlos👑OP•2y ago
client.on('messageCreate', async (message) => {
const prefix = config.client.prefix;
const escapeRegex = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`);
if (!prefixRegex.test(message.content) || message.author.bot || !message.guild) return;
const [, matchedPrefix] = message.content.match(prefixRegex);
const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();

let cmd = client.commands.find((c) => c.name === command || (c.aliases && c.aliases.includes(command)))
if(cmd) {
cmd.run(client, message, args);
}
})
client.on('messageCreate', async (message) => {
const prefix = config.client.prefix;
const escapeRegex = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`);
if (!prefixRegex.test(message.content) || message.author.bot || !message.guild) return;
const [, matchedPrefix] = message.content.match(prefixRegex);
const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();

let cmd = client.commands.find((c) => c.name === command || (c.aliases && c.aliases.includes(command)))
if(cmd) {
cmd.run(client, message, args);
}
})
MrMythical
MrMythical•2y ago
Just switch to slash commands, it will make your life so much easier .-.
-Carlosđź‘‘
-Carlos👑OP•2y ago
i don't like them so what was the issue?
MrMythical
MrMythical•2y ago
idk, we will need more information to actually be able to help
-Carlosđź‘‘
-Carlos👑OP•2y ago
it simply doesn't respond no errors in console
MrMythical
MrMythical•2y ago
ok, but we need actually more information than that Log values, where it stops, etc.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
-Carlosđź‘‘
-Carlos👑OP•2y ago
let me try with that
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
MrMythical
MrMythical•2y ago
The const [, x] destructures the second element in the array
-Carlosđź‘‘
-Carlos👑OP•2y ago
this issue is weird since I have like 15 other command that do similar stuff to this and they work gonna try logging now
MrMythical
MrMythical•2y ago
Slash commands would literally make this so much simpler Regex would not be needed, it's a simple commandName check
-Carlosđź‘‘
-Carlos👑OP•2y ago
fixed it issue was a missing a } in the else if also else {}
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server