J'ai une erreur mais je n'arrive pas à la résoudre.

Mon erreur

G:\Mon Drive\LMC Bot Code\node_modules\@sapphire\shapeshift\dist\index.js:47
    throw this.error;
    ^

ExpectedConstraintError: Invalid string format
    at Object.run (G:\Mon Drive\LMC Bot Code\node_modules\@sapphire\shapeshift\dist\index.js:1592:64)
    at G:\Mon Drive\LMC Bot Code\node_modules\@sapphire\shapeshift\dist\index.js:212:66
    at Array.reduce (<anonymous>)
    at StringValidator.parse (G:\Mon Drive\LMC Bot Code\node_modules\@sapphire\shapeshift\dist\index.js:212:29)
    at validateName (G:\Mon Drive\LMC Bot Code\node_modules\@discordjs\builders\dist\index.js:1402:17)
    at MixedClass.setName (G:\Mon Drive\LMC Bot Code\node_modules\@discordjs\builders\dist\index.js:1499:5)
    at G:\Mon Drive\LMC Bot Code\index.js:26:16
    at MixedClass._sharedAddOptionMethod (G:\Mon Drive\LMC Bot Code\node_modules\@discordjs\builders\dist\index.js:2080:50)
    at MixedClass.addStringOption (G:\Mon Drive\LMC Bot Code\node_modules\@discordjs\builders\dist\index.js:2052:17)
    at Object.<anonymous> (G:\Mon Drive\LMC Bot Code\index.js:25:6) {
  constraint: 's.string.regex',
  given: 'messageType',
  expected: 'expected /^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u.test(expected) to be true'
}

Node.js v18.16.0

Mon code

const { Client, PermissionFlagsBits } = require('discord.js');
const { SlashCommandBuilder } = require('discord.js');
const client = new Client({ intents: 3243773 });
const config = require('./config');
const { token } = require('./token');

const ownerId = "755054105713704960";

client.login(token);

const ping = new SlashCommandBuilder()
    .setName('ping')
    .setDescription('Test command. Send pong.')
    .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages)
    .addUserOption(option =>
        option.setName('utilisateur')
        .setDescription('Ping an user.')
        .setRequired(false));

const message = new SlashCommandBuilder()
    .setName('message')
    .setDescription('Send a message with the bot.')
    .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages)
    .addStringOption((option) => option.setName('message').setDescription('Text to send.').setRequired(true));
    /*.addStringOption(option =>
        option.setName('messageType')
        .setDescription('The message category.')
        .setRequired(true)
        .addChoices(
            { name: 'ID', value: 0 },
            { name: 'Text', value: 1 },
        ))
    .addChannelOption(option =>
        option.setName('channel')
        .setDescription('Chosen channel')
        .setRequired(false))
*/
const dm = new SlashCommandBuilder()
    .setName('dm')
    .setDescription('Send a message to a user with the bot.')
    .addUserOption(option =>
        option.setName('user')
        .setDescription('User to send a message to.')
        .setRequired(true))
    .addStringOption(option =>
        option.setName('message')
        .setDescription('Text to send.')
        .setRequired(true))

const stop = new SlashCommandBuilder()
        .setName('stop')
        .setDescription('Stop the bot')

client.on('ready', async () => {
    client.guilds.cache.get("1107365048797634570").commands.create(ping);
    client.guilds.cache.get("1107365048797634570").commands.create(message);
    client.guilds.cache.get("1107365048797634570").commands.create(stop);
    client.guilds.cache.get("1107365048797634570").commands.create(dm);

    console.log('Connecté sous ' + client.user.tag);
    client.user.setActivity("Regarde LMC Help");
})

client.on("interactionCreate", interaction => {
    if (interaction.isCommand()) {
        switch(interaction.commandName){
            case 'ping':
              //cmd ping
              let utilisateurPing = interaction.options.getUser("utilisateur");
              if(utilisateurPing != undefined){
                interaction.reply("pong <@" + utilisateurPing.id +">");
            }
            else{
                interaction.reply("pong !");
            }
            break;

            case 'dm':
              //cmd dm
              const utilisateurDm = interaction.options.getUser('user'); //comd ping
              const textDm = interaction.options.getString('message'); 

              client.users.send(utilisateurDm, textDm);
              interaction.reply("```" + textDm + "``` a bien été en voyé à " + utilisateurDm);
            break;

            case 'message':
                /*const choiseMessage = interaction.options.getString('messageType');
                const auteurMessage = interaction.user.id
                if(choiseMessage === '0'){
                    let filter = m => m.author.id === message.author.id
                    interaction.reply('ta question').then(messageSent => {
                    interaction.channel.awaitMessages({filter: m => m.author.id == interaction.user.id,  max: 1, time:30000 })
                    .then(collected => {
                    collected.first()?.channel.send("Quel est l'ID du message ?").then(m =>{
                    setTimeout(() => {
                          m.delete()
                        collected.first()?.delete()
                    }, 60000)
                    })
                })})}
                else{
                    collected.first()?.channel.send("Délai dépassé. La commande a été annulé.").then(m =>{
                        setTimeout(() => {
                          m.delete()
                        }, 60000)
                    })

                }
                setTimeout(() => {
                    messageSent.delete()
                }, 600000)
                */

            let message_send = interaction.options.getString("message");

                interaction.reply(message_send)
            break;

            case 'stop':
                if(interaction.user.id === ownerId){
                    interaction.reply('Bot déconnécté')
                    client.destroy();
                }
            break;
        }
    }
});

Je n'en peux plus ça va faire 2 jours que je suis dessus.
Merci pour votre aide.

1 réponse


Hello,

Peut être que je me trompe, mais il semblerait que le code que tu a posté mais pas vraiment en phase avec le context dans lequel se produit l'erreur...

Bref, pour moi l'erreur vient du fait que tu fournis une simple chaine de caractère à "quelque chose" alors que ce "quelque chose" attend une Regex.