ayeuhugyu
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/30/2023 in #djs-questions
functions across modules returning undefined
i have a function in another script (being imported):
being imported and ran from:
the log in the 1st one logs fine, the log in the 2nd one logs undefined
before the bot asks nodejs v19.0.0 discord.js version 14.13.0
(async () => {
const channel = client.channels.cache.get("1148814162273763418");
const msg = await channel.send(message);
console.log(msg + " from sendMainMessage");
return msg;
})();
(async () => {
const channel = client.channels.cache.get("1148814162273763418");
const msg = await channel.send(message);
console.log(msg + " from sendMainMessage");
return msg;
})();
const msg = await action.sendMainMessage("test");
console.log(msg);
const msg = await action.sendMainMessage("test");
console.log(msg);
2 replies
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/28/2023 in #djs-questions
audio player doesn't seem to function
const audioPlayer = createAudioPlayer();
const audioResource = createAudioResource(
"../resources/soundboard/alert.mp3"
);
audioPlayer.on("error", (error) => {
console.log(
"Error:",
error.message,
"with track",
error.resource.metadata.title
);
});
const connection = getVoiceConnection(message.guild.id);
connection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
const audioPlayer = createAudioPlayer();
const audioResource = createAudioResource(
"../resources/soundboard/alert.mp3"
);
audioPlayer.on("error", (error) => {
console.log(
"Error:",
error.message,
"with track",
error.resource.metadata.title
);
});
const connection = getVoiceConnection(message.guild.id);
connection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
4 replies
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/24/2023 in #djs-questions
"invalid string length" error
full code:
code causing the issue:
error:
import discord from "discord.js";
import fs from "fs";
export default {
name: "commands",
description: "displays commands list",
arguments: "none",
execute(message, args) {
let text = "";
const commandFiles = fs
.readdirSync("src/commands/")
.filter((file) => file.endsWith(".js"));
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
console.log(text);
const embed = new discord.EmbedBuilder();
embed.setTitle("PepperBot Commands");
embed.setDescription(text);
embed.setColor(0xff0000);
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
message.reply({ embeds: [embed] });
},
};
import discord from "discord.js";
import fs from "fs";
export default {
name: "commands",
description: "displays commands list",
arguments: "none",
execute(message, args) {
let text = "";
const commandFiles = fs
.readdirSync("src/commands/")
.filter((file) => file.endsWith(".js"));
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
console.log(text);
const embed = new discord.EmbedBuilder();
embed.setTitle("PepperBot Commands");
embed.setDescription(text);
embed.setColor(0xff0000);
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
message.reply({ embeds: [embed] });
},
};
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
8 replies
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/10/2023 in #djs-questions
cannot recieve direct messages
i have partials (which apparently has been the solution for literally everyone else on this planet)
code:
nodejs version 19.0.0, discordjs version 14.13.0
const client = new Client({
intents: [
"Guilds",
"GuildMembers",
"GuildMessages",
"MessageContent",
"DirectMessages",
],
partials: ["Message", "Channel"],
});
client.on("messageCreate", async (message) => {
if (message.channel.type === 1) {
fs.appendFileSync(
"../pepperbot/src/logs/directmessages.log",
"direct message from: " +
message.author.username +
"(" +
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
);
};
};
const client = new Client({
intents: [
"Guilds",
"GuildMembers",
"GuildMessages",
"MessageContent",
"DirectMessages",
],
partials: ["Message", "Channel"],
});
client.on("messageCreate", async (message) => {
if (message.channel.type === 1) {
fs.appendFileSync(
"../pepperbot/src/logs/directmessages.log",
"direct message from: " +
message.author.username +
"(" +
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
);
};
};
23 replies
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/9/2023 in #djs-questions
Attachments
do attachments not work? whenever i try one, it returns the error
node:events:491
throw er; // Unhandled 'error' event
^
TypeError: Cannot use 'in' operator to search for 'size' in ../pepperbot/src/logs/errors.log
at Attachment._patch (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\structures\Attachment.js:34:16)
at new Attachment (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\structures\Attachment.js:24:10)
at Object.execute (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\src\commands\sendlog.js:20:24)
at Client.<anonymous> (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\src\index.js:78:34)
at Client.emit (node:events:513:28)
at MessageCreateAction.handle (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Node.js v19.0.0
node:events:491
throw er; // Unhandled 'error' event
^
TypeError: Cannot use 'in' operator to search for 'size' in ../pepperbot/src/logs/errors.log
at Attachment._patch (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\structures\Attachment.js:34:16)
at new Attachment (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\structures\Attachment.js:24:10)
at Object.execute (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\src\commands\sendlog.js:20:24)
at Client.<anonymous> (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\src\index.js:78:34)
at Client.emit (node:events:513:28)
at MessageCreateAction.handle (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\User\Desktop\VSCode projects\discordjs\pepperbot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Node.js v19.0.0
5 replies
DIAdiscord.js - Imagine an app
•Created by ayeuhugyu on 9/8/2023 in #djs-questions
hosting on raspberry pi
running node index.js on my vscode works fine, no errors
running it on my raspberry pi returns an error
yall got any clue?
node_modules/discord.js/src/client/BaseClient.js:29
userAgentAppendix: options.rest?.userAgentAppendix
^
SyntaxError: Unexpected token "."
at Object.<anonymous> (node_modules/discord.js/src/index.js:6:22)
node_modules/discord.js/src/client/BaseClient.js:29
userAgentAppendix: options.rest?.userAgentAppendix
^
SyntaxError: Unexpected token "."
at Object.<anonymous> (node_modules/discord.js/src/index.js:6:22)
6 replies