I'm still learning Javascript and such, getting into discord.js so I'm pretty sure the code I'm inputting is absolutely wrong and definitely in need of work.
Essentially what I'm looking to do is split up a mand's arguments and separate them into new lines of an embed.
For example, if I was to do: !results "Result 1" "Result 2" "Result 3"
it would output into an embed like table:
RESULTS:
Result 1
Result 2
Result 3
Instead, my output keeps ing out as:
Image of what happens in discord
I have tried various different things from searching on google, but I can't seem to find the thing that I need.
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);
}
}
EDIT: I have made some progress, this is the most recent code and this is the output:
IMAGE
I'm still learning Javascript and such, getting into discord.js so I'm pretty sure the code I'm inputting is absolutely wrong and definitely in need of work.
Essentially what I'm looking to do is split up a mand's arguments and separate them into new lines of an embed.
For example, if I was to do: !results "Result 1" "Result 2" "Result 3"
it would output into an embed like table:
RESULTS:
Result 1
Result 2
Result 3
Instead, my output keeps ing out as:
Image of what happens in discord
I have tried various different things from searching on google, but I can't seem to find the thing that I need.
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);
}
}
EDIT: I have made some progress, this is the most recent code and this is the output:
IMAGE
Share Improve this question edited Jan 9, 2020 at 3:09 Seth Walker asked Jan 8, 2020 at 15:59 Seth WalkerSeth Walker 131 gold badge1 silver badge4 bronze badges 1- Post code so someone can try to take a look at what went wrong. – 0x464e Commented Jan 8, 2020 at 18:02
2 Answers
Reset to default 1You are adding a field, which requires both a title and value. But you are only giving it a value. I'd remend just using the description field and separating your stuff by new lines. It will often times look better. Be sure to keep in mind that the description field is only up to 2048 characters though.
Here's a guide you can take a look at: https://discordjs.guide/popular-topics/embeds.html#embed-preview
In order to parse the arguments you probably have to create a new delimiter, use a ma or something.
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 mand
const mandBody = message.content.slice(prefix.length);
const args = mandBody.split(' ');
const mand = args.shift().toLowerCase();
if(mand === "ping"){
message.channel.send("Hello");
}
if(mand === "test"){
message.channel.send("it is a good day for testing!");
if (args.length > 0) {
message.channel.send("Hello " + args[0]);
}
}
You would change the .split(' ') to something like a ma .split(',')
So the user would enter !test,myName the the bot would reply:
it is a good dat for testing
Hello myName
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041456a4607832.html
评论列表(0条)