简体   繁体   English

在嵌入 discord.js 中设置命令

[英]Setting a command in an embed discord.js

I have looked and I have tried different things, but I cant seem to find an answer that either makes sense or works.我已经看过并且尝试了不同的东西,但我似乎无法找到一个有意义或有效的答案。 I am new to all this in general, but so far stackoverflow has been amazing!一般来说,我对这一切都很陌生,但到目前为止,stackoverflow 一直很棒!

My question is I understand how to create a hyperlink in an embed, but is there way to the embed to work as button that sends a message rather than open up to the web page.我的问题是我了解如何在嵌入中创建超链接,但是有没有办法让嵌入作为发送消息的按钮而不是打开 web 页面。

const Google = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Google')
        .setURL('https://google.com')

At the moment the following embed will link to google.com but is there a way to set it so it sends a ",help" message into the server (which is a separate command within the bot), like something like message.channel.send("!help") I have looked at adding fields and such, but it seems this is the only way to make an embed function as a button/hyperlink.目前,以下嵌入将链接到 google.com,但有没有办法设置它,以便将“帮助”消息发送到服务器(这是机器人中的单独命令),就像message.channel.send("!help")我看过添加字段等,但似乎这是将 function 作为按钮/超链接嵌入的唯一方法。

There is no current way to do this as links are just links.目前没有办法做到这一点,因为链接只是链接。 You can achieve something similar by using awaitReactions() to check if the member has reacted to the embed and sending the message that way:您可以通过使用awaitReactions()检查成员是否对嵌入做出反应并以这种方式发送消息来实现类似的目的:

// Send embed here
message.react('👍').then(() => message.react('👎'));

const filter = (reaction, user) => {
    return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
};

message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '👍') {
            // Send the message here
        }

        else {
            // Optional: Send a message if they don't react with a thumbs up
        }
    })
    .catch(collected => {
        // Also optional: Check if the reacted before timeout
    });

You can find more information regarding reactions here .您可以在此处找到有关反应的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM