Discord Bot - 设置嵌入内容 table/list 并将内容分成几个部分
Discord Bot - Setting up an embed table/list with contents split into sections
我还在学习 Javascript 等等,进入 discord.js 所以我很确定我输入的代码是绝对错误的,绝对需要工作。
基本上我要做的是拆分命令的参数并将它们分成嵌入的新行。
例如,如果我要执行:!results "Result 1" "Result 2" "Result 3"
它将输出到像 table:
这样的嵌入中
RESULTS:
Result 1
Result 2
Result 3
相反,我的输出一直显示为:
Image of what happens in discord
我尝试了各种不同的搜索 google,但我似乎找不到我需要的东西。
const { RichEmbed } = require("discord.js");
module.exports = {
name: "results",
category: "info",
description: "posts results in embed",
usage: "<mention, id>",
run: async (client, message, args) => {
if (message.deletable) message.delete();
let [result1, result2, result3, result4, result5, result6, result7] = args;
if (!args[0])
return message.channel.send("Please provide Result 1.").then(m => m.delete(5000));
if (!args[1])
return message.channel.send("Please provide Result 2.").then(m => m.delete(5000));
if (!args[2])
return message.channel.send("Please provide Result 3.").then(m => m.delete(5000));
if (!args[3])
return message.channel.send("Please provide Result 4.").then(m => m.delete(5000));
if (!args[4])
return message.channel.send("Please provide Result 5.").then(m => m.delete(5000));
if (!args[5])
return message.channel.send("Please provide Result 6.").then(m => m.delete(5000));
if (!args[6])
return message.channel.send("Please provide Result 7.").then(m => m.delete(5000));
const channel = message.guild.channels.find(c => c.name === "cards")
if (!channel)
return message.channel.send("Couldn't find a `#cards` channel").then(m => m.delete(5000));
const embed = new RichEmbed()
.setColor("RANDOM")
.setTimestamp()
.setAuthor("Posted by GM:", (message.author.username, message.author.displayAvatarURL))
.setTitle("**TestTitle**")
.setFooter(message.guild.name, message.guild.iconURL)
.setDescription(`**__Results!__**`)
.addField(`**> Result 1:** ${result1}`)
.addField(`**> Result 2:** ${result2}`)
.addField(`**> Result 3:** ${result3}`)
.addField(`**> Result 4:** ${result4}`)
.addField(`**> Result 5:** ${result5}`)
.addField(`**> Result 6:** ${result6}`)
.addField(`**> Result 7:** ${result7}`);
return channel.send(embed);
}
}
编辑:我取得了一些进展,这是最新的代码,这是输出:
IMAGE
您正在添加一个需要标题和值的字段。但是你只是给它一个值。
我建议只使用描述字段并用新行分隔您的内容。它通常会看起来更好。不过请务必记住,描述字段最多只能 2048 characters。
您可以查看以下指南:
https://discordjs.guide/popular-topics/embeds.html#embed-preview
为了解析参数,您可能必须创建一个新的分隔符,使用逗号或其他东西。
const prefix = "!";
if (message.author.bot) return; // exit processing if author is a bot
if (!message.content.startsWith(prefix)) return; // exit processing if message is not a bot command
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
if(command === "ping"){
message.channel.send("Hello");
}
if(command === "test"){
message.channel.send("it is a good day for testing!");
if (args.length > 0) {
message.channel.send("Hello " + args[0]);
}
}
您可以将 .split(' ') 更改为类似逗号的内容 .split(',')
因此用户将输入 !test,myName
机器人会回复:
it is a good dat for testing
Hello myName
我还在学习 Javascript 等等,进入 discord.js 所以我很确定我输入的代码是绝对错误的,绝对需要工作。
基本上我要做的是拆分命令的参数并将它们分成嵌入的新行。
例如,如果我要执行:!results "Result 1" "Result 2" "Result 3"
它将输出到像 table:
RESULTS:
Result 1
Result 2
Result 3
相反,我的输出一直显示为:
Image of what happens in discord
我尝试了各种不同的搜索 google,但我似乎找不到我需要的东西。
const { RichEmbed } = require("discord.js");
module.exports = {
name: "results",
category: "info",
description: "posts results in embed",
usage: "<mention, id>",
run: async (client, message, args) => {
if (message.deletable) message.delete();
let [result1, result2, result3, result4, result5, result6, result7] = args;
if (!args[0])
return message.channel.send("Please provide Result 1.").then(m => m.delete(5000));
if (!args[1])
return message.channel.send("Please provide Result 2.").then(m => m.delete(5000));
if (!args[2])
return message.channel.send("Please provide Result 3.").then(m => m.delete(5000));
if (!args[3])
return message.channel.send("Please provide Result 4.").then(m => m.delete(5000));
if (!args[4])
return message.channel.send("Please provide Result 5.").then(m => m.delete(5000));
if (!args[5])
return message.channel.send("Please provide Result 6.").then(m => m.delete(5000));
if (!args[6])
return message.channel.send("Please provide Result 7.").then(m => m.delete(5000));
const channel = message.guild.channels.find(c => c.name === "cards")
if (!channel)
return message.channel.send("Couldn't find a `#cards` channel").then(m => m.delete(5000));
const embed = new RichEmbed()
.setColor("RANDOM")
.setTimestamp()
.setAuthor("Posted by GM:", (message.author.username, message.author.displayAvatarURL))
.setTitle("**TestTitle**")
.setFooter(message.guild.name, message.guild.iconURL)
.setDescription(`**__Results!__**`)
.addField(`**> Result 1:** ${result1}`)
.addField(`**> Result 2:** ${result2}`)
.addField(`**> Result 3:** ${result3}`)
.addField(`**> Result 4:** ${result4}`)
.addField(`**> Result 5:** ${result5}`)
.addField(`**> Result 6:** ${result6}`)
.addField(`**> Result 7:** ${result7}`);
return channel.send(embed);
}
}
编辑:我取得了一些进展,这是最新的代码,这是输出:
IMAGE
您正在添加一个需要标题和值的字段。但是你只是给它一个值。 我建议只使用描述字段并用新行分隔您的内容。它通常会看起来更好。不过请务必记住,描述字段最多只能 2048 characters。
您可以查看以下指南: https://discordjs.guide/popular-topics/embeds.html#embed-preview
为了解析参数,您可能必须创建一个新的分隔符,使用逗号或其他东西。
const prefix = "!";
if (message.author.bot) return; // exit processing if author is a bot
if (!message.content.startsWith(prefix)) return; // exit processing if message is not a bot command
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
if(command === "ping"){
message.channel.send("Hello");
}
if(command === "test"){
message.channel.send("it is a good day for testing!");
if (args.length > 0) {
message.channel.send("Hello " + args[0]);
}
}
您可以将 .split(' ') 更改为类似逗号的内容 .split(',')
因此用户将输入 !test,myName 机器人会回复:
it is a good dat for testing
Hello myName