problem with ChannelType.GuildText

when i type this command the console respond me: TypeError: ChannelType.GuildText is not a function
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
ChannelType,
} = require('discord.js');

module.exports = {
name: 'clear',
description: 'Supprime un certain nombre de messages dans un salon.',
options: [
{
name: 'nombre',
description: 'Effacer des messages.',
type: ApplicationCommandOptionType.Integer,
required: true,
},
{
name: 'channel',
description: 'Le channel dans lequel vous souhaitez supprimer les messages.',
type: ApplicationCommandOptionType.Channel,
},
],

permissionsRequired: [PermissionFlagsBits.ManageMessages],
botPermissions: [PermissionFlagsBits.ManageMessages],

callback: async (client, interaction) => {
const channel = interaction.options.getChannel("channel") || interaction.channel;
const number = interaction.options.getInteger("nombre");

if (!ChannelType.GuildText()) {
return interaction.reply({ content: "Vous ne pouvez supprimer des messages que dans un salon texte.", ephemeral: true });
}

if (number <= 0 || number > 100) {
return interaction.reply({ content: "Le nombre doit être compris entre 0 et 100 inclus.", ephemeral: true });
}

await interaction.deferReply();

try {
const messages = await channel.bulkDelete(number);
interaction.followUp({ content: `J'ai bien supprimé \`${messages.size}\` message(s) dans le salon ${channel} !`, ephemeral: true });
} catch (error) {
const messages = [...(await channel.messages.fetch()).filter(msg => !msg.interaction && (Date.now() - msg.createdTimestamp) <= 1209600000).values()];

if (messages.length <= 0) {
return interaction.followUp({ content: "Aucun message à supprimer car ils datent de plus de 14 jours !", ephemeral: true });
}

await channel.bulkDelete(messages);
interaction.followUp({ content: `J'ai pu supprimer uniquement \`${messages.length}\` message(s) dans le salon ${channel} car les autres dataient de plus de 14 jours !`, ephemeral: true });
}
}
}
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
ChannelType,
} = require('discord.js');

module.exports = {
name: 'clear',
description: 'Supprime un certain nombre de messages dans un salon.',
options: [
{
name: 'nombre',
description: 'Effacer des messages.',
type: ApplicationCommandOptionType.Integer,
required: true,
},
{
name: 'channel',
description: 'Le channel dans lequel vous souhaitez supprimer les messages.',
type: ApplicationCommandOptionType.Channel,
},
],

permissionsRequired: [PermissionFlagsBits.ManageMessages],
botPermissions: [PermissionFlagsBits.ManageMessages],

callback: async (client, interaction) => {
const channel = interaction.options.getChannel("channel") || interaction.channel;
const number = interaction.options.getInteger("nombre");

if (!ChannelType.GuildText()) {
return interaction.reply({ content: "Vous ne pouvez supprimer des messages que dans un salon texte.", ephemeral: true });
}

if (number <= 0 || number > 100) {
return interaction.reply({ content: "Le nombre doit être compris entre 0 et 100 inclus.", ephemeral: true });
}

await interaction.deferReply();

try {
const messages = await channel.bulkDelete(number);
interaction.followUp({ content: `J'ai bien supprimé \`${messages.size}\` message(s) dans le salon ${channel} !`, ephemeral: true });
} catch (error) {
const messages = [...(await channel.messages.fetch()).filter(msg => !msg.interaction && (Date.now() - msg.createdTimestamp) <= 1209600000).values()];

if (messages.length <= 0) {
return interaction.followUp({ content: "Aucun message à supprimer car ils datent de plus de 14 jours !", ephemeral: true });
}

await channel.bulkDelete(messages);
interaction.followUp({ content: `J'ai pu supprimer uniquement \`${messages.length}\` message(s) dans le salon ${channel} car les autres dataient de plus de 14 jours !`, ephemeral: true });
}
}
}
4 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna12mo ago
its indeed not a function its a property even if you had it correct, that if statement would always be truthy you want to compare the channel type agains the enum <Channel>.type
Edr0b0t
Edr0b0tOP12mo ago
I've done what you said the command work but the console reply
/home/container/node_modules/@discordjs/rest/dist/index.js:722
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[10008]: Unknown Message
at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1120:23)
at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:953:14)
at async _REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async InteractionWebhook.send (/home/container/node_modules/discord.js/src/structures/Webhook.js:222:15) {
requestBody: {
files: [],
json: {
content: "J'ai bien supprimé `1` message(s) dans le salon #général !",
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/webhooks/1122496790911008829/aW50ZXJhY3Rpb246MTE5OTQxMzQxMTU1NDAwNTExMjp0YktzOHJDMkVIOHdET1lJenA3d0dSUUZCcUE3Wkh3am1rV3hWU096cmlrcFdHYThpaEpTbnZUYXk4RXZlaEdycVRrZmU1aFE3T0hvMjA0clNFZVJ0Y3lqMkhxd2hGQ3ZjTm5la05oWTEzckZTd1RWVHYzYTgzdHRXYm03RlZFVA?wait=true'
}
/home/container/node_modules/@discordjs/rest/dist/index.js:722
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[10008]: Unknown Message
at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1120:23)
at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:953:14)
at async _REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async InteractionWebhook.send (/home/container/node_modules/discord.js/src/structures/Webhook.js:222:15) {
requestBody: {
files: [],
json: {
content: "J'ai bien supprimé `1` message(s) dans le salon #général !",
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/webhooks/1122496790911008829/aW50ZXJhY3Rpb246MTE5OTQxMzQxMTU1NDAwNTExMjp0YktzOHJDMkVIOHdET1lJenA3d0dSUUZCcUE3Wkh3am1rV3hWU096cmlrcFdHYThpaEpTbnZUYXk4RXZlaEdycVRrZmU1aFE3T0hvMjA0clNFZVJ0Y3lqMkhxd2hGQ3ZjTm5la05oWTEzckZTd1RWVHYzYTgzdHRXYm03RlZFVA?wait=true'
}
and here is my code :
const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits, ChannelType } = require('discord.js');

module.exports = {
name: 'clear',
description: 'Supprime un certain nombre de messages dans un salon.',
options: [
{
name: 'nombre',
description: 'Effacer des messages.',
type: ApplicationCommandOptionType.Integer,
required: true,
},
{
name: 'channel',
description: 'Le channel dans lequel vous souhaitez supprimer les messages.',
type: ApplicationCommandOptionType.Channel,
},
],

permissionsRequired: [PermissionFlagsBits.ManageMessages],
botPermissions: [PermissionFlagsBits.ManageMessages],

callback: async (client, interaction) => {
const channel = interaction.options.getChannel("channel") || interaction.channel;
const number = interaction.options.getInteger("nombre");

if (channel.type === ChannelType.GuildText) {
} else {
return interaction.reply({ content: "Vous ne pouvez supprimer des messages que dans un salon texte.", ephemeral: true });
}


if (number <= 0 || number > 100) {
return interaction.reply({ content: "Le nombre doit être compris entre 0 et 100 inclus.", ephemeral: true });
}

await interaction.deferReply();

try {
const messages = await channel.bulkDelete(number);
const response = `J'ai bien supprimé \`${messages.size}\` message(s) dans le salon ${channel} !`;

if (response.length <= 2000) {
interaction.followUp({ content: response, ephemeral: true });
} else {
interaction.followUp({ content: "La réponse est trop longue pour être affichée.", ephemeral: true });
}
} catch (error) {
console.error(error);
interaction.followUp({ content: "Une erreur s'est produite lors de la suppression des messages.", ephemeral: true });
}
}
};
const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits, ChannelType } = require('discord.js');

module.exports = {
name: 'clear',
description: 'Supprime un certain nombre de messages dans un salon.',
options: [
{
name: 'nombre',
description: 'Effacer des messages.',
type: ApplicationCommandOptionType.Integer,
required: true,
},
{
name: 'channel',
description: 'Le channel dans lequel vous souhaitez supprimer les messages.',
type: ApplicationCommandOptionType.Channel,
},
],

permissionsRequired: [PermissionFlagsBits.ManageMessages],
botPermissions: [PermissionFlagsBits.ManageMessages],

callback: async (client, interaction) => {
const channel = interaction.options.getChannel("channel") || interaction.channel;
const number = interaction.options.getInteger("nombre");

if (channel.type === ChannelType.GuildText) {
} else {
return interaction.reply({ content: "Vous ne pouvez supprimer des messages que dans un salon texte.", ephemeral: true });
}


if (number <= 0 || number > 100) {
return interaction.reply({ content: "Le nombre doit être compris entre 0 et 100 inclus.", ephemeral: true });
}

await interaction.deferReply();

try {
const messages = await channel.bulkDelete(number);
const response = `J'ai bien supprimé \`${messages.size}\` message(s) dans le salon ${channel} !`;

if (response.length <= 2000) {
interaction.followUp({ content: response, ephemeral: true });
} else {
interaction.followUp({ content: "La réponse est trop longue pour être affichée.", ephemeral: true });
}
} catch (error) {
console.error(error);
interaction.followUp({ content: "Une erreur s'est produite lors de la suppression des messages.", ephemeral: true });
}
}
};
treble/luna
treble/luna12mo ago
You're either deleting more messages than the channel have, not sure whether that would produce that error, or, this seems more likely, you're deleting the deferReply message
Want results from more Discord servers?
Add your server