Reputation: 13
I made a suggestion feature for my discord where users can say +suggest
(suggestion) and it will auto post to another channel.
There are things I need help with:
+suggest
at the start.Here's my code for the embedding:
module.exports.run = async (bot, message, args) => {
let suggestembed = new Discord.RichEmbed()
.addField("Suggestion made by:", message.author)
.addField("Suggestion:", message.content)
.setTimestamp()
Here's a picture of what it looks like:
https://gyazo.com/48e5c34fa463615180143403e52d5f49
Upvotes: 1
Views: 664
Reputation: 4349
1
RichEmbed.addField()
takes in two parameters: A title, and the content. By using .addField("Suggestion made by:", message.author)
you are setting the title to be "Suggestion made by:"
and the content to be message.author
. To put everything into a single line, you can do .addField("Suggestion made by:" + message.author, '')
This sets the title to be what you want, and keep content empty. You can also put this in the content parameter, but note that the title cannot be empty. IF it is, it will return an error.
Solution:
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
You can remove the prefix using multiple methods. Here are a few.
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)
Hope this helped!
Upvotes: 1
Reputation: 81
To handle the issue of +suggest appearing you could split the message away from it's prefix.
const args = message.content.slice(1).trim().split(/ +/g);
let suggestion = args.slice(0).join(" ");
Instead of using fields you could just set it in the description. Like this:
let suggestembed = new Discord.RichEmbed()
.setDescription(`**Suggestion made by:** ${message.author}\n**Suggestion:** ${suggestion}`)
.setTimestamp()
I'm not able to test this right now, it should work. Let me know if there are any issues.
Upvotes: 0