Home > Software design >  Is there a way to split up a message based off special characters?
Is there a way to split up a message based off special characters?

Time:04-25

I am currently trying to make a discord bot with a command title "reactionrole". In this command I would like to let the user create an embed using a single message. For example, (-reactionrole "title blah blah" / "description blah blah" / "role1" "role2" / "emoji1" "emoji2") would be sent as a Discord message. Here's what I've tried so far

name: 'reactionrole',
    description: "Sets up a reaction role message!",
    async execute(message:any, args:any, Discord:any, client:any) {
        const slicePoint = ('/');
        var segments = message.content.includes(slicePoint.length).split(slicePoint);
         var msg = message.content;
         var segments = msg.split('/');
         var firstRole = message.guild.roles.cache.find((role:any) => role.name === segments[2]);
         var firstEmoji = segments[3];
         var secondRole = message.guild.roles.cache.find((role:any) => role.name === segments[2]);
         var secondEmoji = segments[3];

let embed = new Discord.MessageEmbed()
         .setTitle(segments[0])
         .setDescription(segments[1])

and then there'd also be some reactions that would be added based off Segments 2 and 3 but I already know how to make that. If anyone could help that'd be amazing

CodePudding user response:

So you mean like a separator?



const separated = message.content.slice(prefix.length).trim().split(" / ")
console.log(separated[1])
//This should serve what you're trying to achieve
// If I send a message like !separate hello :) / there, if u log them, you'd get 'hello :)' and 'there' separately
 

CodePudding user response:

I suspect the problem is the use of message as an identifier conflicting with the built-in Window.message event. Use another identifier.

  • Related