我为我的不和提出了一项建议功能,用户可以说+suggest
(建议),它将自动发布到另一个频道。
有些事情我需要帮助:
+suggest
。这是我的嵌入代码:
module.exports.run = async (bot, message, args) => {
let suggestembed = new Discord.RichEmbed()
.addField("Suggestion made by:", message.author)
.addField("Suggestion:", message.content)
.setTimestamp()
这是它的外观图片:
答案 0 :(得分:1)
1
RichEmbed.addField()
具有两个参数:标题和内容。通过使用.addField("Suggestion made by:", message.author)
,您可以将标题设置为"Suggestion made by:"
,将内容设置为message.author
。要将所有内容放在一行中,您可以执行.addField("Suggestion made by:" + message.author, '')
,这会将标题设置为您想要的内容,并使内容为空。您也可以将其放在content参数中,但是请注意标题不能为空。如果是,它将返回错误。
解决方案:
module.exports.run = async (bot, message, args) => {
let suggestembed = new Discord.RichEmbed()
.addField("Suggestion made by:" + message.author, '')
.addField("Suggestion:", message.content)
.setTimestamp();
OR
module.exports.run = async (bot, message, args) => {
let suggestembed = new Discord.RichEmbed()
.addField("MyTitle", "Suggestion made by" + message.author)
.addField("Suggestion:", message.content)
.setTimestamp();
2
您可以使用多种方法删除前缀。这里有一些。
message.content.split("+suggest")[1]
str.substr()
切掉前缀:message.content.substr("+suggest".length)
str.substring()
切掉前缀:message.content.substring("+suggest".length)
str.slice()
切掉前缀:message.content.slice("+suggest".length)
希望这对您有帮助!
答案 1 :(得分:0)
要处理+ uggest出现的问题,您可以将消息从其前缀中分离出来。
const args = message.content.slice(1).trim().split(/ +/g);
let suggestion = args.slice(0).join(" ");
您可以仅在描述中设置它,而不是使用字段。像这样:
let suggestembed = new Discord.RichEmbed()
.setDescription(`**Suggestion made by:** ${message.author}\n**Suggestion:** ${suggestion}`)
.setTimestamp()
我现在无法测试,它应该可以工作。让我知道是否有任何问题。