Problem with db.function when running any command - javascript

I am having a problem with db.function on messageCreate.js, before the bot was running pretty much okay, it does run okay now, but when I write a comment into discord let's say prefixplay waka waka or something it does give me that error however, I haven't even changed it before, I am running discord.js#13.12.0
can someone explain what the problem is?
Here is the code I have in MessageCreate.js
module.exports = async (client, message) => {
try {
module.exports.messageGET = message;
if (message.channel.type == "DM") return;
let data = db.fetch(`SeTupInFo_${message.guild.id}`);
if (data !== null) {
if (message.channel.id == data.channelID) {
message.delete();
if (message.guild.me.voice.channel) {
if (message.member.voice.channel !== message.guild.me.voice.channel)
return message.reply({
content: emojis.error + " | please join a voice channel first!",
});
}
Here is the error I am getting when I run any command
TypeError: db.fetch is not a function
at module.exports (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\source\events\messageCreate.js:19:19)
at Client.emit (node:events:537:28)
at MessageCreateAction.handle (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\discord.js\src\client\actions\MessageCreate.js:25:14)
at module.exports [as MESSAGE_CREATE] (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\discord.js\src\client\websocket\WebSocketManager.js:350:31)
at WebSocketShard.onPacket (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at C:\Users\ramyo\Downloads\latestbottest1_feb-main\latestbottest1_feb-main\node_modules\#discordjs\voice\dist\index.js:604:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I tried many thinks, and even also tried downgrade dependencies to my old ones that were working before, its some think not expecting any output that the command is working please help thank you.

Assuming that's a valid function, my guess would be that db hasn't been imported properly. Try something like const db = require('db-package') at the top of the file.

Related

discord auto role when status matches

Ive tries some different things to make this work but it's not wanting to work
so am basicly trying to check someones custom status for a specific thing if there is for example .gg/test in it and give them a role than
My code
client.on('presenceUpdate', async (oldPresence, newPresence) => {
const role = newPresence.guild.roles.cache.get("927284722059595828");
const member = newPresence.member
const activities = member.user.presence.activities[0];
if (activities && (activities.state.includes( ".gg/test" ) || activities.state.includes("discord.gg/test" ))) {
return newPresence.member.roles.add(role)
} else {
if(member.roles.cache.get(role.id)) {
newPresence.member.roles.remove(role)
}
}
})
so can anyone correct the code to the correct format
and if possable make this multi server usable with a command thanks
the error i get
TypeError: Cannot read properties of undefined (reading 'id')
at Client.<anonymous> (/root/raegay2/boy.js:19:36)
at Client.emit (node:events:390:28)
at PresenceUpdateAction.handle (/root/raegay2/node_modules/discord.js/src/client/actions/PresenceUpdate.js:39:19)
at Object.module.exports [as PRESENCE_UPDATE] (/root/raegay2/node_modules/discord.js/src/client/websocket/handlers/PRESENCE_UPDATE.js:4:33)
at WebSocketManager.handlePacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/root/raegay2/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (/root/raegay2/node_modules/ws/lib/websocket.js:825:20)
I just tested your code and it worked fine. Did you enable Presence Intent on your bots discord developer page? If you are using Gateway Intents, you must specify the GUILD_PRESENCES intent in order to receive Presence Update events.

Discord.js throws ReferenceError: message is not defined

I am in the process of making a bot that has features that only work on a specific server. The server is about trading cards, and I want to make a bot that can moderate the server, and that people can have fun with.
The error looks like this:
c:\Users\REDACTED\Desktop\Sky\index.js:10
if (message.content === 'sky claim') {
^
ReferenceError: message is not defined
at Client.<anonymous> (c:\Users\kelly\Desktop\Sky\index.js:10:3)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\websocket.js:845:20)
The code for my Discord bot is here.
client.on("message", (msg) => {
if (message.content === "sky claim") {
message.channel.send("${message.author} claimed 250 SkyBucks. Spend SkyBucks on colored roles.");
console.log("${message.author} executed command successfully");
}
});`
I only added the part of the code that was giving the error.
If you read your error you should be able to find out why it doesn’t work:
client.on('message', message => {
if (message.content === 'sky eBay') {
message.channel.send('Our eBay store is #CollectAmazing, I will drop a link:');
message.channel.send('https://www.ebay.com/str/collectamazing');
}
})
Change all of the client.on('message', msg to client.on('message', message

Getting an error on Discord JS "cannot read property of 'content' undefined"

CODE IS BELOW
I have a simple discord bot and added a message file under events--guild
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);
if(command) commmand.execute(client, message, args, Discord);
}
```
Just Incase You need it here is my main file
```
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{;
require(`./handlers/${handler}`)(client, Discord)
})
client.login('My Token');
full error below
TypeError: Cannot read property 'content' of undefined
at Object.module.exports (E:\Software\Discord Bots\BombBot\events\guild\message.js:3:17)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (E:\Software\Discord Bots\BombBot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
About: this discord bot is a simple bot that I am trying do with a command and event handler as I am new to discord js and not to javascript, I tried to see if there was a few issues, but couldn't find any. The debug window can't help either because its a value/variable that shows as undefined but is defined above.
as I am a bit new I used the tutorial: https://www.youtube.com/watch?v=Sihf7B8D4Y8 and rewrote the code multiple times. If you have an idea please tell me before I rewrite it again.
The Debugger is below
E:\Software\node JS\node.exe .\index.js
BOT Is ONLINE
events/client/ready.js:4
Uncaught TypeError: Cannot read property 'content' of undefined
No debugger available, can not send 'variables'
Process exited with code 1
It's hard to determine the origin of the error based on the info you provided.
The message content is not guaranteed. Messages from other bots that are embeds have no content, thus it's undefined. To fix this, add Optional Chaining in your condition:
if(!message.content?.startsWith(prefix) || message.author.bot) return;
If that doesn't work, that probably means your message object is not Discord Message at all. Make sure you pass the arguments to your function correctly.

newMember.guild.channels.cache.find not working in my discord bot's code

I am trying to make a Discord bot for a friend. The purpose of the bot would be to add a role to any member of a specific voice channel and remove it when they leave the channel. Here is the code:
client.on('voiceStateUpdate', (oldMember, newMember) => {
// définition des constantes
const testChannel = newMember.guild.channels.cache.find(c => c.name === '🕐 1h de travail');
const role = newMember.guild.roles.cache.find(r => r.name === 'test');
// détection
if (newMember.channelID === testChannel.id) {
// Triggered when the user joined the channel we tested for
if (!newMember.member.roles.cache.has(role))
newMember.member.roles.add(role);
// Add the role to the user if they don't already have it
}
else if (oldMember.member.roles.cache.has(role))
oldMember.member.roles.remove(role);
}
});
When I launch the bot using npm run dev and then join a voice channel, I get this error:
/home/archie/Documents/my-bot/index.js:13
const testChannel = newMember.guild.channels.cache.find(c => c.name === '🕐 1h de travail');
^
TypeError: Cannot read property 'find' of undefined
at Client.<anonymous> (/home/archie/Documents/my-bot/index.js:13:56)
at Client.emit (node:events:379:20)
at VoiceStateUpdateHandler.handle (/home/archie/Documents/my-bot/node_modules/discord.js/src/client/websocket/packets/handlers/VoiceStateUpdate.js:40:16)
at WebSocketPacketManager.handle (/home/archie/Documents/my-bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:108:65)
at WebSocketConnection.onPacket (/home/archie/Documents/my-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:336:35)
at WebSocketConnection.onMessage (/home/archie/Documents/my-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:299:17)
at WebSocket.onMessage (/home/archie/Documents/my-bot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (node:events:379:20)
at Receiver.receiverOnMessage (/home/archie/Documents/my-bot/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (node:events:379:20)
[nodemon] app crashed - waiting for file changes before starting...
I don't understand it and would really appreciate your help.
It looks like you're using discord.js v11 with code written for v12. In the older version, guild.channels was a Collection, not a Manager so it doesn't have a cache property. That's why it's undefined and that's why you can't use .find on it.
All you need to do is update your discord.js to the latest version.
PS: If you're using discord.js v12, the client.voiceStateUpdate event returns oldState and newState instead of oldMember, and newMember. So, it returns the VoiceState of the member before and after the update, not the member itself.

Discord.js - getting a GuildMember's displayName gives me a TypeError

I really don't know what's going on here. My code is inside the Akairo Framework but the error points in every direction to discord.js itself. Here's the error:
/home/runner/guard/Listeners/automod/nicknames.js:14
if (message.member.displayName.includes(word)) {
^
TypeError: Cannot read property 'displayName' of null
at module.exports.exec (/home/runner/guard/Listeners/automod/nicknames.js:14:32)
at Client.emit (events.js:327:22)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateAction.handle (/home/runner/guard/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/guard/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/guard/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/guard/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/guard/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/guard/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
This is my code: (bannedWords is an array of strings that I run through to check against the member's nickname) (it's inside a message event listener)
const bannedWords = require('./badwords.json').words;
for (const word of bannedWords) {
if (message.member.displayName.includes(word)) {
message.member.setNickname(`Moderated Nickname`)
}
}
There is a bit of a logical flaw in your code: you do not check if the message was sent in DMs. If the message was indeed a DM, then message.member would be null (as DM channels are not part of any server), which pretty much explains your error.
You should fix this by either explicitly checking (and returning) if the channel is a DM, or if it is a falsy value
//some code ...
if(!message.member) return;
for (const word of bannedWords) {
if (message.member.displayName.includes(word)) {
message.member.setNickname(`Moderated Nickname`)
}
}
TypeError: Cannot read property 'displayName' of null
This means "message.member" is null and it cannot find the property "displayName", which then makes sense.
I think we need to see more of your code in order to figure out where it went wrong. I'm guessing you are trying to run that if statement on a member object that doesn't exist.

Categories