fenya
fenya
DIAdiscord.js - Imagine an app
Created by fenya on 8/13/2024 in #djs-questions
Getting "Unknown message" sometimes...
yo. Excluding command handling I have something like this:
client.on("interactionCreate", (interaction: Interaction) => {
// if interaction is component I run execution method
const loadingContent = loadingEmoji ? `<a:${loadingEmoji.name}:${loadingEmoji.id}>` : "...";
const message = await interaction.reply({ content: loadingContent, ephemeral: true, fetchReply: true }) : null;
reply(opts: ...) {
delete opts .ephemeral;
await message.edit(opts as ...);
}
// here are some actions. they are takes 2-30secs
// and at the end I run reply function to send a message
const error = await reply({ content: null, embeds: [...], files: [...] }).then(() => null).catch((e: Error) => e);
// sometimes error is null, sometimes its not
});
client.on("interactionCreate", (interaction: Interaction) => {
// if interaction is component I run execution method
const loadingContent = loadingEmoji ? `<a:${loadingEmoji.name}:${loadingEmoji.id}>` : "...";
const message = await interaction.reply({ content: loadingContent, ephemeral: true, fetchReply: true }) : null;
reply(opts: ...) {
delete opts .ephemeral;
await message.edit(opts as ...);
}
// here are some actions. they are takes 2-30secs
// and at the end I run reply function to send a message
const error = await reply({ content: null, embeds: [...], files: [...] }).then(() => null).catch((e: Error) => e);
// sometimes error is null, sometimes its not
});
4 replies
DIAdiscord.js - Imagine an app
Created by fenya on 1/4/2023 in #djs-questions
How is it possible that the Message's author is equivalent to null?
TypeError: Cannot read properties of null (reading 'id')
at Object.execute (D:\bot\dist\events\messageDelete.js:12:28)
at DiscordClient.<anonymous> (D:\bot\dist\handlers\events.js:43:54)
at DiscordClient.emit (node:events:513:28)
at MessageDeleteAction.handle (D:\bot\node_modules\discord.js\src\client\actions\MessageDelete.js:24:16)
TypeError: Cannot read properties of null (reading 'id')
at Object.execute (D:\bot\dist\events\messageDelete.js:12:28)
at DiscordClient.<anonymous> (D:\bot\dist\handlers\events.js:43:54)
at DiscordClient.emit (node:events:513:28)
at MessageDeleteAction.handle (D:\bot\node_modules\discord.js\src\client\actions\MessageDelete.js:24:16)
Error reffers to
const discord_js_1 = require("discord.js");
const EmbedBuilder_1 = __importDefault(require("../structures/overwrite/EmbedBuilder"));
const event = {
name: discord_js_1.Events.MessageDelete,
once: false,
async execute(client, message) {
if (message.author.id == client.user.id) return;
^
const discord_js_1 = require("discord.js");
const EmbedBuilder_1 = __importDefault(require("../structures/overwrite/EmbedBuilder"));
const event = {
name: discord_js_1.Events.MessageDelete,
once: false,
async execute(client, message) {
if (message.author.id == client.user.id) return;
^
Generated from
const event: BaseEvent = {
name: Events.MessageDelete,
once: false,
async execute(client: Client, message: Message) {
if (message.author.id == client.user.id) return;
const event: BaseEvent = {
name: Events.MessageDelete,
once: false,
async execute(client: Client, message: Message) {
if (message.author.id == client.user.id) return;
8 replies
DIAdiscord.js - Imagine an app
Created by fenya on 8/28/2022 in #djs-questions
Access error using a channel deletion method
Yo. When I add my bot to the guild I request ManageChannels & ManageRoles permissions. Right now on my test server I found a rather strange error.
voiceChannel.delete()
.then(() => {
// posting result to logs
})
.catch((e) => {
console.error(e);
// posting error to logs
});
voiceChannel.delete()
.then(() => {
// posting result to logs
})
.catch((e) => {
console.error(e);
// posting error to logs
});
If I right now execute this function with current perms. The channel will be successfully deleted. --- I wanted to add a command to block this channel. I execute it like this:
voiceChannel.permissionOverwrites.cache.forEach(async (perm) => {
if (perm.type == OverwriteType.Role) {
if (perm.id != interaction.guild.members.me.roles?.botRole?.id) {
channel.permissionOverwrites.edit(perm.id, { 'Connect': dbChannel.locked }).catch(() => {});
} else {
// do nothing for now
}
}
});
voiceChannel.permissionOverwrites.cache.forEach(async (perm) => {
if (perm.type == OverwriteType.Role) {
if (perm.id != interaction.guild.members.me.roles?.botRole?.id) {
channel.permissionOverwrites.edit(perm.id, { 'Connect': dbChannel.locked }).catch(() => {});
} else {
// do nothing for now
}
}
});
But after executing this command, the bot loses the ability to delete this channel.
DiscordAPIError[50001]: Missing Access
...
{
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'DELETE',
url: 'https://discord.com/api/v10/channels/1013544243534504067',
requestBody: { files: undefined, json: undefined }
}
DiscordAPIError[50001]: Missing Access
...
{
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'DELETE',
url: 'https://discord.com/api/v10/channels/1013544243534504067',
requestBody: { files: undefined, json: undefined }
}
I checked the permissions of the bot before blocking the channel - and after. Didn't notice the difference.
3 replies
DIAdiscord.js - Imagine an app
Created by fenya on 8/27/2022 in #djs-questions
How can I check if I can overwrite channel permissions?
I prefer to check permissions before acting. So if I want to create a channel I check
if (categoryChannel.permissionsFor(guild.members.me).has([ PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.ManageChannels ], true)) {
// ok
}
if (categoryChannel.permissionsFor(guild.members.me).has([ PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.ManageChannels ], true)) {
// ok
}
So, how can I check if I can overwrite channel permissions? In what situations might a bot not have enough perms to perform this action? What kind of bitField is needed to execute lockPermissions()?
10 replies