有没有办法根据特殊字符拆分消息?
Is there a way to split up a message based off special characters?
我目前正在尝试制作一个命令标题为“reactionrole”的不和谐机器人。在此命令中,我想让用户使用一条消息创建嵌入。例如,(-reactionrole "title blah blah" / "description blah blah" / "role1" "role2" / "emoji1" "emoji2") 将作为 Discord 消息发送。这是我到目前为止尝试过的方法
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])
然后还会根据第 2 部分和第 3 部分添加一些反应,但我已经知道如何制作了。如果有人能提供帮助那就太好了
所以你的意思是像一个分隔符?
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
我怀疑问题是使用 message
作为标识符与 built-in Window.message
事件冲突。使用其他标识符。
我目前正在尝试制作一个命令标题为“reactionrole”的不和谐机器人。在此命令中,我想让用户使用一条消息创建嵌入。例如,(-reactionrole "title blah blah" / "description blah blah" / "role1" "role2" / "emoji1" "emoji2") 将作为 Discord 消息发送。这是我到目前为止尝试过的方法
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])
然后还会根据第 2 部分和第 3 部分添加一些反应,但我已经知道如何制作了。如果有人能提供帮助那就太好了
所以你的意思是像一个分隔符?
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
我怀疑问题是使用 message
作为标识符与 built-in Window.message
事件冲突。使用其他标识符。