discord bot mute command

example .mute @Ashleydafox 5m i try 1s something 10m, 15m 20d, const { PermissionFlagsBits } = require("discord.js"); const ms = require("ms"); module.exports = { name: "mute", description: "Mutes (timeouts) a user for a specified duration.", async execute(message, args) { try { // ✅ Check if the user running the command has "Timeout Members" permission if (!message.member.permissions.has(PermissionFlagsBits.ModerateMembers)) { return message.reply("❌ You do not have permission to timeout members!"); } // ✅ Get bot's member object and check its permissions const botMember = await message.guild.members.fetchMe(); if (!botMember.permissions.has(PermissionFlagsBits.ModerateMembers)) { return message.reply("❌ I need the 'Timeout Members' permission to mute users!"); } // ✅ Ensure a user is provided (mention or ID) if (!args[0]) { return message.reply("❌ Please provide a user mention or ID to mute!"); } const target = message.mentions.members.first() await message.guild.members.fetch(args[0]).catch(() => null); if (!target) { return message.reply("❌ Invalid user! Please mention a valid user or provide their ID."); } // ✅ Ensure a duration was provided if (!args[1]) { return message.reply("❌ Please specify a duration (e.g., 1s, 5m, 2h, 4d)."); } // ✅ Extract the time argument (ignores case sensitivity) let timeArg = args[1].toLowerCase(); // ✅ If only a number is given, assume minutes if (!isNaN(timeArg)) { timeArg = ${timeArg}m; // Default to minutes if no unit is provided } const timeMs = ms(timeArg); // ✅ Validate the parsed time if (!timeMs timeMs < 1000) { // Minimum timeout: 1 second return message.reply("❌ Invalid time format! Example: 1s, 30s, 5m, 2h, 7d."); } // ✅ Ensure the time does not exceed Discord’s max timeout (28 days) const maxTimeout = 2419200000; // 28 days in milliseconds if (timeMs > maxTimeout) { return message.reply("❌ You cannot mute someone for more than 28 days!"); } // ✅ Ensure the bot can actually mute (timeout) the user if (!target.moderatable) { return message.reply("❌ I can't timeout this user! They might have a higher role than me."); } // ✅ Check role hierarchy if (target.roles.highest.position >= botMember.roles.highest.position) { return message.reply("❌ I can't timeout this user because their role is equal to or higher than mine."); } // ✅ Apply the timeout await target.timeout(timeMs, Muted by ${message.author.tag}); return message.reply(✅ **${target.user.tag}** has been muted (timed out) for **${ms(timeMs, { long: true })}**.); } catch (error) { console.error("Mute command error:", error); return message.reply("❌ Failed to mute (timeout) the user!"); } } }; thats the cide
26 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2w ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
will a text file work
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
okay just makung sure
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
https://sourceb.in/ar55SVc853 okay so .mute @Ashleydafox 5m borx APP — Today at 10:02 PM ❌ Invalid time format! Example: 1s, 30s, 5m, 2h, 7d. basically the command doesnt mute i been trying to make it work for hours i got ban,kick to work
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
i can invite you to the server and show you and i can show the files for it and all
Syjalo
Syjalo2w ago
You have two spaces after the mention
nameless
namelessOP2w ago
No description
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
yes multiple times bc i couldn't get it to actually work
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
partly yes simple things are easy
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
nameless
namelessOP2w ago
wait so do yk what's wrong with the code.. this is the only thing that isn't working on the bot
Syjalo
Syjalo2w ago
It's not your code issue ^
nameless
namelessOP2w ago
lemme retry still giving the same error Target: simon_the_foxcat Time Argument: <@1007058569889320982> Parsed Time in ms: undefined Target: simon_the_foxcat Time Argument: <@1007058569889320982> Parsed Time in ms: undefined
Syjalo
Syjalo2w ago
Log your args and see what is wrong
nameless
namelessOP2w ago
:/home/container$ if [[ -d .git ]] && [[ ${AUTO_UPDATE} == "1" ]]; then git pull; fi; if [[ ! -z ${NODE_PACKAGES} ]]; then /usr/local/bin/npm install ${NODE_PACKAGES}; fi; if [[ ! -z ${UNNODE_PACKAGES} ]]; then /usr/local/bin/npm uninstall ${UNNODE_PACKAGES}; fi; if [ -f /home/container/package.json ]; then /usr/local/bin/npm install; fi; /usr/local/bin/node /home/container/${JS_FILE} There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=<remote>/<branch> main up to date, audited 95 packages in 3s 21 packages are looking for funding run npm fund for details 4 moderate severity vulnerabilities To address issues that do not require attention, run: npm audit fix To address all issues (including breaking changes), run: npm audit fix --force Run npm audit for details. Server is ready. Bot is online! Logged in as borx#4648 Command Used: mute Arguments Received: [ 'mute', '@Ashleydafox', '5m', 'yes' ] Command Used: mute Arguments Received: [ 'mute', '<@1007058569889320982>', '10m', 'yes' ] Target: simon_the_foxcat (1007058569889320982) Time Argument: <@1007058569889320982> Parsed Time in ms: undefined short verison Server is ready. Bot is online! Logged in as borx#4648 Command Used: mute Arguments Received: [ 'mute', '@Ashleydafox', '5m', 'yes' ] Command Used: mute Arguments Received: [ 'mute', '<@1007058569889320982>', '10m', 'yes' ] Target: simon_the_foxcat (1007058569889320982) Time Argument: <@1007058569889320982> Parsed Time in ms: undefined
Syjalo
Syjalo2w ago
So you have the command name in your first arg. Shift it in your command handler
nameless
namelessOP2w ago
No description
No description
nameless
namelessOP2w ago
YOOOOOOOOOOOOOOOO Command Used: mute Arguments Received: [ '@Ashleydafox', '10m', 'ye' ] Command Used: mute Arguments Received: [ '<@1007058569889320982>', '5m', 'yes' ] Target: simon_the_foxcat (1007058569889320982) Time Argument: 5m Parsed Time in ms: 300000 ✅ simon_the_foxcat has been muted for 5 minutes YESSSS @Syjalo ty

Did you find this page helpful?