Discord.js can't register context menu - javascript

I've been messing around with discord.js and wanted to add a context menu to my bot, for some reason whenever I start the bot I get this really weird error, I can't seem to solve it or find a solution online, here's the code:
const { ContextMenuCommandBuilder } = require(`#discordjs/builders`);
module.exports = {
data: new ContextMenuCommandBuilder()
.setName(`test`)
.setType(`MESSAGE`),
async execute(interaction) {
interaction.reply({
content: `Successful.`,
ephemeral: true
});
}
}
And here's the error:
C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:1470
return Result.err(new CombinedError(errors));
^
CombinedError: Received one or more errors
at UnionValidator.handle (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:1470:23)
at UnionValidator.parse (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:113:88)
at validateType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1462:17)
at ContextMenuCommandBuilder.setType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1484:5)
at Client.<anonymous> (C:\Users\willi\OneDrive\Desktop\NovaBotAI\NovaBot.js:65:14)
at Object.onceWrapper (node:events:642:26)
at Client.emit (node:events:527:28)
at WebSocketManager.triggerClientReady (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17)
at WebSocketManager.checkShardsReady (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\discord.js\src\client\websocket\WebSocketManager.js:367:10)
at WebSocketShard.<anonymous> (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\discord.js\src\client\websocket\WebSocketManager.js:189:14) {
errors: [
ExpectedValidationError: Expected values to be equals
at LiteralValidator.handle (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:674:76)
at LiteralValidator.run (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:102:23)
at UnionValidator.handle (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:1465:32)
at UnionValidator.parse (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:113:88)
at validateType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1462:17)
at ContextMenuCommandBuilder.setType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1484:5)
at Client.<anonymous> (C:\Users\willi\OneDrive\Desktop\NovaBotAI\NovaBot.js:65:14)
at Object.onceWrapper (node:events:642:26)
at Client.emit (node:events:527:28)
at WebSocketManager.triggerClientReady (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17) {
validator: 's.literal(V)',
given: 'MESSAGE',
expected: 2
},
ExpectedValidationError: Expected values to be equals
at LiteralValidator.handle (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:674:76)
at LiteralValidator.run (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:102:23)
at UnionValidator.handle (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:1465:32)
at UnionValidator.parse (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#sapphire\shapeshift\dist\index.js:113:88)
at validateType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1462:17)
at ContextMenuCommandBuilder.setType (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\#discordjs\builders\dist\index.js:1484:5)
at Client.<anonymous> (C:\Users\willi\OneDrive\Desktop\NovaBotAI\NovaBot.js:65:14)
at Object.onceWrapper (node:events:642:26)
at Client.emit (node:events:527:28)
at WebSocketManager.triggerClientReady (C:\Users\willi\OneDrive\Desktop\NovaBotAI\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:17) {
validator: 's.literal(V)',
given: 'MESSAGE',
expected: 3
}
]
}
I'm at a loss, nothing I do seems to fix it, I tried changing the setType() value to a number and that got the code to start, but then it didn't register and I couldn't use it at all, but other than that I've got nothing.

You probably have fixed that already, but I have experienced the same issue today and solved it. I'm gonna post the solution, in case someone else needs it..
const { ContextMenuCommandBuilder } = require(`#discordjs/builders`);
const { ApplicationCommandType } = require('discord-api-types/v9');
module.exports = {
data: new ContextMenuCommandBuilder()
.setName(`test`)
.setType(ApplicationCommandType.Message),
async execute(interaction) {
interaction.reply({
content: `Successful.`,
ephemeral: true
});
}
}

If you are using module.exports why don't you use the command directly like:
const { client, ContextMenuInteraction } = require('discord.js');
module.exports = {
name: "...",
type: 'USER',

Related

Can't use Lyrics slash command, I'm getting an "s." error

return Result.err(new CombinedError(errors));
^
CombinedError: Received one or more errors
at UnionValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:1051:23)
at UnionValidator.parse (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:106:88)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/#discordjs/builders/dist/index.js:228:20)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/discord.js/src/structures/EmbedBuilder.js:22:18)
at Object.run (/home/shifty/bot-3/commands/lyrics.js:33:12)
at /home/shifty/bot-3/events/interactionCreate.js:62:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
errors: [
ExpectedValidationError: Expected values to be equals
at LiteralValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:692:76)
at LiteralValidator.run (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:92:23)
at UnionValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:1046:32)
at UnionValidator.parse (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:106:88)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/#discordjs/builders/dist/index.js:228:20)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/discord.js/src/structures/EmbedBuilder.js:22:18)
at Object.run (/home/shifty/bot-3/commands/lyrics.js:33:12)
at /home/shifty/bot-3/events/interactionCreate.js:62:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.literal(V)',
given: undefined,
expected: null
},
ValidationError: Expected a number primitive
at NumberValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:859:70)
at NumberValidator.run (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:92:23)
at UnionValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:1046:32)
at UnionValidator.parse (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:106:88)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/#discordjs/builders/dist/index.js:228:20)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/discord.js/src/structures/EmbedBuilder.js:22:18)
at Object.run (/home/shifty/bot-3/commands/lyrics.js:33:12)
at /home/shifty/bot-3/events/interactionCreate.js:62:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.number',
given: undefined
},
ValidationError: Expected an array
at TupleValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:1682:25)
at TupleValidator.run (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:92:23)
at UnionValidator.handle (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:1046:32)
at UnionValidator.parse (/home/shifty/bot-3/node_modules/#sapphire/shapeshift/dist/index.js:106:88)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/#discordjs/builders/dist/index.js:228:20)
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/discord.js/src/structures/EmbedBuilder.js:22:18)
at Object.run (/home/shifty/bot-3/commands/lyrics.js:33:12)
at /home/shifty/bot-3/events/interactionCreate.js:62:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.tuple(T)',
given: undefined
}
]
}
I made a Discord music bot and I made a lyric command for it and I'm getting this error
This is the error I get every time I run the lyrics command, it's an error I think occurs because the code itself is not correct?
in that case here's the lyric command's code:
const { EmbedBuilder, ApplicationCommandOptionType } = require("discord.js");
const { get } = require("node-superfetch");
const config = require("../config.js");
const db = require("../mongoDB");
module.exports = {
name: "lyrics",
description: "Gets the lyrics of a song.",
userPerms: [],
player: true,
dj: false,
inVoiceChannel: true,
sameVoiceChannel: true,
options: [
{
name: "song",
description: "Song name to return lyrics for.",
type: ApplicationCommandOptionType.String,
required: false,
},
],
/**
*
* #param {Client} client
* #param {CommandInteraction} interaction
*/
run: async (client, interaction) => {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor(client.embedColor)
.setDescription("🔎 **Searching...**"),
],
});
let player;
if (client.manager) {
player = client.manager.players.get(interaction.guild.id);
} else {
return interaction.reply({
embeds: [
new EmbedBuilder()
.setColor("Red")
.setDescription("Node not connected"),
],
});
}
const args = interaction.options.getString("song");
if (!args && !player) {
return interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor("Red")
.setDescription("There's no music playing."),
],
});
}
let search = args ? args : player.queue.current.title;
let url = `https://api.darrennathanael.com/lyrics?song=${search}`;
let lyrics = await get(url);
if (!lyrics || lyrics.status !== 200) {
return interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor("Red")
.setDescription(
`❌ | No lyrics found for ${search}!\nMake sure you entered your search correctly.`
),
],
});
}
let text = lyrics.body.lyrics;
let lyricsEmbed = new EmbedBuilder()
.setColor(client.embedColor)
.setTitle(`${lyrics.body.full_title}`)
.setURL(lyrics.url)
.setThumbnail(lyrics.body.thumbnail)
.setDescription(text);
if (text.length > 4096) {
text = text.substring(0, 4090) + "[...]";
lyricsEmbed
.setDescription(text)
.setFooter({ text: "Truncated, the lyrics were too long." });
}
return await interaction.editReply({ embeds: [lyricsEmbed] });
},
};
I tried adding const to new EmbedBuilder which didn't work out
The error says you are passing undefined when it expects something else. It's easy to read these errors if you know how.
ExpectedValidationError: Expected values to be equals
-- internal files --
at EmbedBuilder.setColor (/home/shifty/bot-3/node_modules/discord.js/src/structures/EmbedBuilder.js:22:18) -----> The function you called
at Object.run (/home/shifty/bot-3/commands/lyrics.js:33:12) -----> Where the error occurs - your file
at /home/shifty/bot-3/events/interactionCreate.js:62:26
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.literal(V)', -----> What it expects
given: undefined, -----> What you passed
expected: null -----> More information on what it expects, if the validator is not clear enough
Since none of these matched, it throws the error. If you look on line 33 of lyrics.js, as said in the stack trace, you'll see .setColor(client.embedColor). This means client.embedColor is undefined. It's not a native discord.js property, so I assume you either meant to set it, and failed to do so, or accessed the property incorrectly.

i getting error Cannot read property 'channels' of undefined

I'm getting an error Cannot read property 'channels' of undefined
(node:2632) UnhandledPromiseRejectionWarning: TypeError: Cannot read
property 'channels' of undefined
at updateMembers (C:\Users\Asus\Desktop\Episode 50\commands\Main-Commands\Mod\member-count.js:5:31)
at module.exports (C:\Users\Asus\Desktop\Episode 50\commands\Main-Commands\Mod\member-count.js:13:5)
at Client. (C:\Users\Asus\Desktop\Episode 50\index.js:48:5)
at Object.onceWrapper (events.js:421:28)
at Client.emit (events.js:315:20)
at WebSocketManager.triggerClientReady (C:\Users\Asus\Desktop\Episode
50\node_modules\discord.js\src\client\websocket\WebSocketManager.js:431:17)
at WebSocketManager.checkShardsReady (C:\Users\Asus\Desktop\Episode
50\node_modules\discord.js\src\client\websocket\WebSocketManager.js:415:10)
at WebSocketShard. (C:\Users\Asus\Desktop\Episode 50\node_modules\discord.js\src\client\websocket\WebSocketManager.js:197:14)
at WebSocketShard.emit (events.js:315:20)
at WebSocketShard.checkReady (C:\Users\Asus\Desktop\Episode 50\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
Here is my code:
module.exports = (client) => {
const membercountchannel = '811119579580465182'
const updateMembers = (guild) => {
const channel = guild.channels.cache.get(membercountchannel)
channel.setName(`Member:- ${guild.memberCount.toLocaleString()}`)
}
client.on('guildMemberAdd', (member) => updateMembers(member.guild))
client.on('guildMemberRemove', (member) => updateMembers(member.guild))
const guild = client.guilds.cache.get('787083837833871400')
updateMembers(guild)
}
If you check the stack trace, you can see that your updateMembers function receives a guild that is undefined (member-count.js:5:31). On the next line you can see that it's coming from the last line (member-count.js:13:5): updateMembers(guild).
As you define guild one line above, it means client.guilds.cache.get('787083837833871400') returns undefined. Make sure the guild ID is correct. If it is correct, you can try to fetch the guild instead.
One more thing, you should never add event handlers inside event handlers. I think you're already in client.on('message'). Every time someone's using your command to update the member count, you create two new event listeners (client.on('guildMemberAdd') and client.on('guildMemberRemove')) and it will cause issues (memory leaks). You need to handle these somewhere else, outside of your commands.
module.exports = async (client) => {
const updateMembers = (guild) => {
const memberCountChannel = '811119579580465182';
const channel = guild.channels.cache.get(memberCountChannel);
channel.setName(`Member:- ${guild.memberCount.toLocaleString()}`);
};
try {
const guild = await client.guilds.fetch('787083837833871400');
updateMembers(guild);
} catch (error) {
console.log(error);
}
};

Discord.js ReferenceError: channel is not defined

I'm using the discordjs bot guide and copied their help command from the GitHub. However the code gives an error. I've tried almost every solution I could find for the ReferenceError I'm getting. What am I doing wrong?
My code:
const { prefix } = require('../../config.json');
module.exports = {
name: 'help',
description: 'List all of my commands or info about a specific command.',
aliases: ['commands'],
usage: '[command name]',
cooldown: 5,
execute(message, args) {
const data = [];
const { commands } = message.client;
if (!args.length) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);
return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like I can\'t DM you!');
});
}
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
if (!command) {
return message.reply('that\'s not a valid command!');
}
data.push(`**Name:** ${command.name}`);
if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
if (command.description) data.push(`**Description:** ${command.description}`);
if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
message.channel.send(data, { split: true });
},
};
The error:
ReferenceError: channel is not defined
at Object.execute (C:\Users\user\JS Bot\commands\utility\help.js:64:5)
at Client.<anonymous> (C:\Users\user\JS Bot\index.js:78:11)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\user\JS Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\user\JS Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\user\JS Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\user\JS Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\user\JS Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\user\JS Bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)

(Discord.js) TypeError: Cannot read property 'add' of undefined

So here's the code:
const mutedRole = message.guild.roles.cache.find(role => role.name === "Muted");
if (!mutedUser) return message.channel.send()
if (!message.author) return;
if (!mutedRole) {
message.guild.roles.create({
data: {
name: 'Muted',
color: '#6C877C',
permissions: ["CREATE_INSTANT_INVITE", "VIEW_CHANNEL"],
},
})
.catch(console.error);
}
mutedUser.roles.add(mutedRole).catch(console.error);
When I run the bot, I get the error:
2020-08-14T05:22:08.731213+00:00 app[Worker.1]: TypeError: Cannot read property 'add' of undefined
2020-08-14T05:22:08.731236+00:00 app[Worker.1]: at Object.execute (/app/commands/mute.js:69:29)
2020-08-14T05:22:08.731236+00:00 app[Worker.1]: at Client.<anonymous> (/app/bread.js:111:14)
2020-08-14T05:22:08.731238+00:00 app[Worker.1]: at Client.emit (events.js:315:20)
2020-08-14T05:22:08.731239+00:00 app[Worker.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-08-14T05:22:08.731241+00:00 app[Worker.1]: at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-08-14T05:22:08.731242+00:00 app[Worker.1]: at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-08-14T05:22:08.731242+00:00 app[Worker.1]: at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
2020-08-14T05:22:08.731242+00:00 app[Worker.1]: at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
2020-08-14T05:22:08.731243+00:00 app[Worker.1]: at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:125:16)
2020-08-14T05:22:08.731244+00:00 app[Worker.1]: at WebSocket.emit (events.js:315:20)
As seen on the code, I add the part where the bot would make a role as when the role is unavailable. But still, it thinks as that the role never exist.
Before this was copied, I aslo wrote the code like this:
if (!mutedRole) {
guild.roles.create({
data: {
name: 'Muted',
color: '#6C877C',
permissions: ["CREATE_INSTANT_INVITE", "VIEW_CHANNEL"],
},
})
.catch(console.error);
}
And the result is still the same. I also put the bot's role on the most top list of all roles on my test server. Can anyone find out why?
I'm currently using discord.js v12 and stable version of node.
Note: full code here: https://github.com/centralomd/breadbot/blob/master/commands/mute.js
The error comes from line 14:
const mutedUser = message.mentions.users.first() || message.guild.members.get(args[0])
If there are no mentions in the message.mentions.users Collection, you are trying to get a GuildMember using message.guild.members.get().
Discord JS v12 introduces the concept of managers, you will no longer be able to directly use Collection methods such as Collection.get() on data structures like Client.users and Guild.members.
You'll have to change it with:
const mutedUser = message.mentions.users.first() || message.guild.members.cache.get(args[0])
if (!mutedUser) return message.channel.send("Invalid user.");
Note: message.mentions.users will get users in other guilds as well. I recommend you to use message.mentions.members.

Discord.js Bot crashing while used command

my problem is when i write command! Tempmute (user) (time) and in field (time) i'll write for example 10 s / m / h / d it works great but when i wrote other letter in this field bot just crash.
Can any one tell me how to fix it? Thanks in advance!
Code:
if (command === `${prefix}tempmute`) {
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!tomute) return message.reply("Nie moge znaleźć określonego użytkownika");
if(tomute.hasPermission("ADMINISTRATOR")) return message.reply("Ta osoba ma zbyt wysoką rangę lub nie masz permisji!");
let muterole = message.guild.roles.find(r => r.name === "muted");
if(!muterole){
try {
muterole = message.guild.createRole({
name: "muted",
color: "#0000000",
permissions: []
})
message.guild.channels.forEach(async (channel, id) => {
channel.overwritePermissions(muterole,{
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
} catch(e) {
console.log(e.stack);
}
}
let mutetime = args[1];
if(!mutetime) return message.reply("Wprowadź czas na jaki ma byc zmutowana osoba")
tomute.addRole(muterole.id);
message.reply(`<#${tomute.id}> został zmutowany na ${ms(ms(mutetime))}`);
setTimeout(function(){
tomute.id.removeRole(muterole.id);
message.channel.send(`<#${tomute.id}> został odmutowany!`);
}, ms(mutetime));
}
}
);
Error in console:
C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\ms\index.js:34
throw new Error(
^
Error: val is not a non-empty string or a valid number. val=undefined
at module.exports (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\ms\index.js:34:9)
at Client.<anonymous> (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\bot.js:241:58)
at Client.emit (events.js:210:5)
at MessageCreateHandler.handle (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:210:5)
at Receiver.receiverOnMessage (C:\Users\pr0mo\OneDrive\Pulpit\Discord Rust Bot\node_modules\ws\lib\websocket.js:789:20)
Add your code to the try catch statement it won't crash anymore, but if you want to check if the argument corresponds to what you want, you can make an regexp
try catch:
try
{
}catch(error)
{
console.log(error)
}
Regex:
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
mutetime);
if(!match)return;

Categories

Resources