如何在 Discord 中创建一个接受用户输入的弹出窗口?

西菲尔斯

这是我第一次从 Discord 机器人中看到此功能。我试着到处寻找,但似乎我失败了。Captcha.bot Discord bot 提供了此功能,您可以在其中接受来自 Discord 内弹出窗口的输入。

Captcha.bot 制作的嵌入式消息中有一个按钮,您必须在其中回答验证码测试。按下按钮后,它会创建一个像这样的弹出窗口。

在此处输入图像描述

在验证码机器人上放置正确答案后,这是体验的后果。

在此处输入图像描述

我想学习的是如果可能的话,如何使用 Discord.js 召唤那个弹出窗口,或者至少了解他们是如何做到的。

佐尔特·梅萨罗斯

这些被称为模态,它们将在下一个 discord.js 版本 v14 中可用。已经有一个拉请求

同时,您可以使用 npm 包,例如discord- modals或discordjs-modal

discord-modals您可以在下面的包中找到一个工作示例。不要忘记先使用npm i discord-modals.

const {
  Client,
  Intents,
  MessageActionRow,
  MessageButton,
} = require('discord.js');
const discordModals = require('discord-modals');
const { Modal, TextInputComponent, showModal } = discordModals;

const TOKEN = 'YOUR TOKEN HERE';
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
discordModals(client);

client.on('messageCreate', (message) => {
  if (message.author.bot) return;

  let button = new MessageActionRow();
  button.addComponents(
    new MessageButton()
      .setCustomId('verification-button')
      .setStyle('PRIMARY')
      .setLabel('Open modal dialog'),
  );
  message.reply({
    components: [button],
  });
});

client.on('interactionCreate', async (interaction) => {
  if (interaction.isButton()) {
    if (interaction.customId === 'verification-button') {
      const modal = new Modal() // We create a Modal
        .setCustomId('verification-modal')
        .setTitle('Verify yourself')
        .addComponents([
          new TextInputComponent()
            .setCustomId('verification-input')
            .setLabel('Answer')
            .setStyle('SHORT')
            .setMinLength(4)
            .setMaxLength(12)
            .setPlaceholder('ABCDEF')
            .setRequired(true),
        ]);

      showModal(modal, {
        client,
        interaction,
      });
    }
  }
});

client.on('modalSubmit', async (modal) => {
  if (modal.customId === 'verification-modal') {
    const response = modal.getTextInputValue('verification-input');
    modal.reply(`Yay, your answer is submitted: "${response}"`);
  }
});

client.once('ready', () => {
  console.log('Bot v13 is connected...');
});

client.login(TOKEN);

在此处输入图像描述

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Pyqt5 Python中打开另一个窗口并接受用户输入

我如何在discord.py中接受用户输入

如何创建一个Siri Intent来接受用户传递的输入

如何创建一个接受用户输入的子程序?

如何接受用户输入以创建类的另一个实例?(即根据用户规范添加员工?)

如何接受用户输入,但将其全部重定向到另一个文件?

如何在 PowerShell Plus 中创建一组接受用户输入的文件夹

如何在嵌入的消息 Discord.py 中接受用戶輸入

如何在jshell脚本中接受用户输入?

如何在swift和xcode中接受用户输入

如何在discord.py中创建一个包含多个单词的命令?

如何在 discord.js 中创建一个改变状态的命令?

如何为 discord bot 中的每个用户创建一个变量。不和谐.py

如何在python discord bot中获得用户输入?

如何在discord.py中检查用户的创建日期?

如何在 Discord.py 中循环?

如何在XLSForm内创建一个弹出窗口?

如何使用Packer创建一个接受用户数据的自定义Linux AMI

如何在Python脚本中接受管道输入,然后接受用户提示的输入?

(Discord.js)如何在类别内创建一个新的文本通道?

在discord.py中,如何将多个单词设置为一个参数,但仍然要求用户输入一个参数?

如何在discord.py中获取用户标签?

如何在discord.py中响应错误的用户命令

您如何在discord.js中定义用户的颜色?

如何在Discord.py中获取用户的ID

如何在 discord.py 中禁止/踢出多个用户?

如何在 discord.py 中创建投资组合命令?

如何在discord.js中创建删除角色的命令

如何在 Discord.js 中创建“+提及”命令