【问题标题】:How can I add Embed message from an array discord.js?如何从数组 discord.js 添加嵌入消息?
【发布时间】:2021-10-14 08:27:56
【问题描述】:

我制作了一个关于真心话大冒险的机器人。当我键入 +t 时,它会发送我添加的事实之一。现在我想发送真相或敢于嵌入 像这样 embed truths or dares

那么我该怎么做呢?请记住,我将使用 embed 回复数组中的随机数据 我的代码

// Array of possible truth replies
const t = [
    "If you could be invisible, what is the first thing you would do?", 
    "What's the strangest dream you've ever had?",
    "What are the top three things you look for in a boyfriend/girlfriend?",
    "What is your worst habit?",
    "How many stuffed animals do you own?",
    "What is your biggest insecurity?"
];

// Array of possible dare replies
const d = [
    "Do a free-style rap for the next minute.",
    "Let another person post a status on your behalf.",
    "Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
    "Let the other players go through your phone for one minute.",
    "Smell another player's armpit",
    "Smell another player's barefoot.",
    "Tell everyone your honest opinion of the person who sent this command."
];

// Handle all commands here
client.on('message', message => {

    // Don't reply to itself
    if (message.author.id === client.user.id) return;

    // If there is no + (prefix) at the beginning of the message, exit function
    if (!message.content.startsWith(prefix)) return;

    // Remove the prefix from the message -> our command
    const command = message.content.substring(prefix.length);

    // Match the command
    if (command === "t") { // Truth
        const truth = t[Math.floor(Math.random() * t.length)];
        message.channel.send(truth);
    } else if (command === "d") { // Dare
        const dare = d[Math.floor(Math.random() * d.length)];
        message.channel.send(dare);
    } else if (command === "help") { // Help

        const help = new Discord.MessageEmbed()
            .setColor('#72dfa3')
            .setTitle(`Truth Or Dare`)
            .addFields(
                { name: '``+help``', value: 'For help' },
                { name: '``+t``', value: 'For Truth' },
                { name: '``+d``', value: 'For Your Dare' },
                { name: '``Created By``', value: 'AlpHa Coder [Labib Khan]' },
            )
            .setTimestamp()
            .setFooter(`${message.author.username}`, message.author.displayAvatarURL());

        message.channel.send(help);

    } else { // No match found, invalid command
        message.channel.send("Invalid command, type `+help` for help.");
    }

});

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

你只需要像在帮助命令中那样使用嵌入。

代码如下:

if (command === "t") { // Truth
    const truth = t[Math.floor(Math.random() * t.length)];
    message.channel.send(new Discord.MessageEmbed()
        .setTitle("Truth")
        .setDescription(truth));
} else if (command === "d") { // Dare
    const dare = d[Math.floor(Math.random() * d.length)];
    message.channel.send(new Discord.MessageEmbed()
        .setTitle("Dare")
        .setDescription(dare));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 2021-12-13
    • 2021-11-07
    • 1970-01-01
    • 2021-01-09
    • 2021-08-25
    • 2018-08-26
    相关资源
    最近更新 更多