X_DigitalNinja
X_DigitalNinja
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 8/27/2024 in #djs-questions
API Not showing the right player ammount
[
{
"shard_id": 0,
"is_ready": true,
"latency": -1,
"server_count": 8,
"cached_user_count": 3,
"uptime": 6801
}
]
[
{
"shard_id": 0,
"is_ready": true,
"latency": -1,
"server_count": 8,
"cached_user_count": 3,
"uptime": 6801
}
]
So my API is only showing 3 user count but there is way and way more in my main guild so I am really confused as to why my API code
js
app.get('/status', async (req, res) => {
try {
if (!client.isReady()) {
return res.status(503).json({ error: 'Bot is not ready' });
}

const shardStatuses = await client.shard.broadcastEval(async (client) => {
const server_count = client.guilds.cache.size;
const member_counts = await Promise.all(client.guilds.cache.map(guild => guild.memberCount));
const total_member_count = member_counts.reduce((a, b) => a + b, 0);

return {
shard_id: client.shard.ids[0],
is_ready: client.isReady(),
latency: client.ws.ping,
server_count: server_count,
cached_user_count: total_member_count,
uptime: client.uptime,
};
});

res.json(shardStatuses);
} catch (error) {
Logger.error('Error fetching shard status:', error);
res.status(500).json({ error: 'Failed to fetch shard status' });
}
});
js
app.get('/status', async (req, res) => {
try {
if (!client.isReady()) {
return res.status(503).json({ error: 'Bot is not ready' });
}

const shardStatuses = await client.shard.broadcastEval(async (client) => {
const server_count = client.guilds.cache.size;
const member_counts = await Promise.all(client.guilds.cache.map(guild => guild.memberCount));
const total_member_count = member_counts.reduce((a, b) => a + b, 0);

return {
shard_id: client.shard.ids[0],
is_ready: client.isReady(),
latency: client.ws.ping,
server_count: server_count,
cached_user_count: total_member_count,
uptime: client.uptime,
};
});

res.json(shardStatuses);
} catch (error) {
Logger.error('Error fetching shard status:', error);
res.status(500).json({ error: 'Failed to fetch shard status' });
}
});
13 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 8/23/2024 in #djs-questions
Timeout command
I am trying to get my timeout command to work but I keep getting > ERROR [22:21:32] Error while executing timeout command: Cannot read properties of undefined (reading 'getUser') and when I get that away it does show everything properly but the command does not get the user timeout I am not sure if its the Rest API or something else any help with me very much helpful
js
js
15 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 8/22/2024 in #djs-questions
Ping command
So I am a bit confused so I so I am new to using d.js/@core and d.js/@rest Witch I am fully using and I am having issues making my ping command work
import { SlashCommandBuilder } from "@discordjs/builders";
import { MessageFlags, InteractionType } from "@discordjs/core";
import { config } from "../../../config.js";
import guildModel from "../../models/guild.js";

export default {
data: new SlashCommandBuilder().setName("ping").setDescription("Get the bot's ping").setDMPermission(false),

async execute(interaction, api) {
try {
if (interaction.type !== InteractionType.ApplicationCommand) {
throw new Error("Unsupported interaction type.");
}

let guildData = await guildModel.findOne({ guildId: interaction.guild_id }).catch(() => null);

const wsPing = interaction.client?.ws?.ping;
const apiLatency = Date.now() - interaction.createdTimestamp;

const fields = [];

if (typeof wsPing === "number") {
fields.push({ name: "WebSocket Latency", value: `${wsPing}ms`, inline: true });
} else {
fields.push({ name: "WebSocket Latency", value: `Unable to fetch`, inline: true });
}

if (!isNaN(apiLatency)) {
fields.push({ name: "API Latency", value: `${apiLatency}ms`, inline: true });
} else {
fields.push({ name: "API Latency", value: `Unable to fetch`, inline: true });
}

const pingEmbed = {
color: parseInt(guildData?.color ?? config.colors.main),
title: `Pong! 🏓`,
fields: fields,
footer: {
text: "Cosmo Bot",
},
};

await api.interactions.reply(interaction.id, interaction.token, {
embeds: [pingEmbed],
flags: MessageFlags.Ephemeral | MessageFlags.SuppressNotifications,
});

} catch (err) {
if (!interaction.replied && !interaction.deferred) {
try {
await api.interactions.reply(interaction.id, interaction.token, {
content: `An error occurred while executing the command. Please try again later.`,
flags: MessageFlags.Ephemeral | MessageFlags.SuppressNotifications,
});
} catch (replyError) {

}
}
}
},
};
import { SlashCommandBuilder } from "@discordjs/builders";
import { MessageFlags, InteractionType } from "@discordjs/core";
import { config } from "../../../config.js";
import guildModel from "../../models/guild.js";

export default {
data: new SlashCommandBuilder().setName("ping").setDescription("Get the bot's ping").setDMPermission(false),

async execute(interaction, api) {
try {
if (interaction.type !== InteractionType.ApplicationCommand) {
throw new Error("Unsupported interaction type.");
}

let guildData = await guildModel.findOne({ guildId: interaction.guild_id }).catch(() => null);

const wsPing = interaction.client?.ws?.ping;
const apiLatency = Date.now() - interaction.createdTimestamp;

const fields = [];

if (typeof wsPing === "number") {
fields.push({ name: "WebSocket Latency", value: `${wsPing}ms`, inline: true });
} else {
fields.push({ name: "WebSocket Latency", value: `Unable to fetch`, inline: true });
}

if (!isNaN(apiLatency)) {
fields.push({ name: "API Latency", value: `${apiLatency}ms`, inline: true });
} else {
fields.push({ name: "API Latency", value: `Unable to fetch`, inline: true });
}

const pingEmbed = {
color: parseInt(guildData?.color ?? config.colors.main),
title: `Pong! 🏓`,
fields: fields,
footer: {
text: "Cosmo Bot",
},
};

await api.interactions.reply(interaction.id, interaction.token, {
embeds: [pingEmbed],
flags: MessageFlags.Ephemeral | MessageFlags.SuppressNotifications,
});

} catch (err) {
if (!interaction.replied && !interaction.deferred) {
try {
await api.interactions.reply(interaction.id, interaction.token, {
content: `An error occurred while executing the command. Please try again later.`,
flags: MessageFlags.Ephemeral | MessageFlags.SuppressNotifications,
});
} catch (replyError) {

}
}
}
},
};
9 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 9/14/2023 in #djs-questions
Ban command
I seem to be having this issue when trying to ban someone outside the server I have been trying to find a way to ban outside the server for a bit but could not do it Here is my code https://pastebin.com/Kw7GQbWt
18 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 9/13/2023 in #djs-questions
Badges
So I am having this issue with badges, I want my badges to go by row but it seems the badges keep colliding together,
8 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 9/10/2023 in #djs-questions
Trying to get the ban command to work
I have been having issues with my ban command for some time I need it so I can ban their ID and also mention them within the command this is so I can ban them outside the server. Here is my code https://pastebin.com/Mzmh1dmH
3 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 9/8/2023 in #djs-questions
Ban command.
How do I make my ban command work with Banning their Discord ID and when you mention them within the slash command. https://pastebin.com/iqeQZJbP
27 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 8/29/2023 in #djs-questions
TypeError: MessageEmbed is not a constructor
I seem to keep getting this error when trying to setup the DM when they get banned I get this error 2|Fireball Beta | Error while banning: TypeError: MessageEmbed is not a constructor 2|Fireball Beta | at module.exports (/mnt/volume_tor1_01/Fireball-beta/src/commands/moderation/ban.js:26:19) 2|Fireball Beta | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) this is my code https://pastebin.com/6gVzzqUi
6 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 7/21/2023 in #djs-questions
How to create timestamps
But how Do I make this into a timestamp
.addFields({ name: "Date Created", value: `${guild.createdAt}`, inline: true})
.addFields({ name: "Date Created", value: `${guild.createdAt}`, inline: true})
This is for server info and I need it to show the date and time in a timestamp
5 replies
DIAdiscord.js - Imagine an app
Created by X_DigitalNinja on 4/5/2023 in #djs-questions
Dm user Error
Been getting this error and can not seem to see why it won't work
DiscordAPIError[50007]: Cannot send messages to this user
at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async DMChannel.send (/home/container/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:157:15)
at async Client.<anonymous> (/home/container/index.js:80:9) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [Array],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Cannot send messages to this user', code: 50007 },
code: 50007,
status: 403,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1093025064749908138/messages'
}
DiscordAPIError[50007]: Cannot send messages to this user
at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async DMChannel.send (/home/container/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:157:15)
at async Client.<anonymous> (/home/container/index.js:80:9) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [Array],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Cannot send messages to this user', code: 50007 },
code: 50007,
status: 403,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1093025064749908138/messages'
}
5 replies