Discord 嵌入动态帮助命令的内容
因此,我使用discord文档编写了一个动态帮助命令。但是为了让它引人注目,我想将它嵌入并显示到用户DM中。 以下是一个小片段-Discord 嵌入动态帮助命令的内容,discord,discord.js,Discord,Discord.js,因此,我使用discord文档编写了一个动态帮助命令。但是为了让它引人注目,我想将它嵌入并显示到用户DM中。 以下是一个小片段- execute(client, message, args) { const data = []; const { commands } = message.client; if (!args.length) { data.push('Here\'s a list of all my comma
execute(client, message, args) {
const data = [];
const { commands } = message.client;
if (!args.length) {
data.push('Here\'s a list of all my commands:'); //push on data var to append the info you want
data.push(commands.map(command => command.name).join('\n'));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);
return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
});
}
我是否可以在嵌入中使用data.push 您的意思是制作一个嵌入并显示所有命令名吗 我是否可以使用data.push嵌入 不确定你的确切意思,但据我所知,不,嵌入有字段、文件、标题等属性,你可以设置这些属性,而不是使用当前的数据数组方法 这可能是您想要的:
execute(客户端、消息、参数){
常量数据=[];
const{commands}=message.client;
如果(!参数长度){
//您需要以某种方式引用它,比如const{MessageEmbed}=require(“discord.js”)
const embed=new MessageEmbed()
.setTitle(“这是我所有命令的列表:”);
.setDescription(commands.map(cmd=>cmd.name).join(“\n”));
.setFooter(`youcan send`${prefix}help[command name]\`获取特定命令的信息!`);
返回message.author.send(数据,{split:true})
.然后(()=>{
if(message.channel.type==='dm')返回;
message.reply('我已经向您发送了一个包含我所有命令的DM!');
})
.catch(错误=>{
错误(`无法将帮助DM发送到${message.author.tag}.\n`,错误);
message.reply('好像我不能为您DM!您是否禁用了DMs?');
});
}
}
如果您认为数据长度将超过1024个字符,请尝试执行以下操作:
const embed = new Discord.MessageEmbed()
.setTitle("Command List :")
.setColor("GREEN");
var tempDesc = "";
for (let line of data) {
if ((tempDesc + line).length < 1024) tempDesc += line
else {
message.channel.send(embed.setDescription(tempDesc));
tempDesc = "";
}
}
if (tempDesc.length > 0) message.channel.send(embed.setDescription(tempDesc));
const embed=new Discord.MessageEmbed()
.setTitle(“命令列表:”)
.setColor(“绿色”);
var tempDesc=“”;
用于(让数据行){
如果((tempDesc+行)。长度<1024)tempDesc+=行
否则{
message.channel.send(embed.setDescription(tempDesc));
tempDesc=“”;
}
}
if(tempDesc.length>0)message.channel.send(embed.setDescription(tempDesc));
我以前也有同样的问题,但我已经解决了
if (!args.length) {
const title = 'Here\'s a list of all my commands:';
const description = data.push(commands.map(command => command.name).join(', '));
const footer = `You can send ${prefix}help [command name] to get info on a specific command!`;
const helpEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
.setTitle(title)
.setDescription(data)
.setTimestamp()
.setFooter(footer);
return message.author.send(helpEmbed)
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
});
试试这个。它应该会起作用
if (!args.length) {
const title = 'Here\'s a list of all my commands:';
const description = data.push(commands.map(command => command.name).join(', '));
const footer = `You can send ${prefix}help [command name] to get info on a specific command!`;
const helpEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
.setTitle(title)
.setDescription(data)
.setTimestamp()
.setFooter(footer);
return message.author.send(helpEmbed)
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
});