如何在JavaScript中读取用户内容condordbot

发布于 2025-02-07 21:28:14 字数 989 浏览 0 评论 0原文

您好,我为一个Discord聊天机器人编程,当命令“!help”将定向到某个文本频道时,该机器人将直接给写命令的人写一条直接消息,以回答一系列问题,这是代码我现在做的是:

const {Client, RichEmbed, Intents, MessageEmbed} = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
 
const token = 'TOKEN';
 
const PREFIX = '!';
 
 
bot.on('ready', () => {
    console.log(`Logged in as ${bot.user.tag}!`);
})

bot.on('messageCreate', message => {
    let args = message.content.substring(PREFIX.length).split(" ");
    
    switch (args[0]) { 
        case 'help':
            const Embed = new MessageEmbed()
            .setTitle("Helper Embed")
            .setColor(0xFF0000)
            .setDescription("Make sure to use the !help to get access to the commands");
 
            message.author.send(Embed);
        break;
    }
 
});
                            
bot.login(token);

机器人写信给请求该命令的用户的DM,但我无法解决,根据用户回答的内容,机器人响应与其他信息,并且用户可以用反应回答。

Hello im programming a discord chat bot, that when the command '!help' is directed to a certain text channel, the bot writes a direct message to the person who wrote the command in order to answer a series of questions, this is the code that I did for now:

const {Client, RichEmbed, Intents, MessageEmbed} = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
 
const token = 'TOKEN';
 
const PREFIX = '!';
 
 
bot.on('ready', () => {
    console.log(`Logged in as ${bot.user.tag}!`);
})

bot.on('messageCreate', message => {
    let args = message.content.substring(PREFIX.length).split(" ");
    
    switch (args[0]) { 
        case 'help':
            const Embed = new MessageEmbed()
            .setTitle("Helper Embed")
            .setColor(0xFF0000)
            .setDescription("Make sure to use the !help to get access to the commands");
 
            message.author.send(Embed);
        break;
    }
 
});
                            
bot.login(token);

The bot writes to the DM of the user that requested the command, but I have not been able to solve, that according to what the user answers, the robot response with other information, and also that the user can answer with reactions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下的泡沫是彩色的 2025-02-14 21:28:14

如果您只想等待一些消息,则可以使用 等待 。它有一些选项,例如要等待的消息数,收集消息的时间和可选过滤器。一个示例:

const filter = (message) => {
    // Do some validation
}
message.channel.awaitMessages({
    time: '', // The time the collector is valid for in milliseconds
    max: '', // The number of messages the collector will wait for
    filter,
    error: ['time'] // Give an error when the timer runs out so the .catch function runs
}).then(collected => console.log(collected)) // Console log all the collected messages
.catch(collected => console.log(`${collected.size} messages were collected`))

但是,如果您正在使用按钮,则简单 MessageComponentCollector 会做。即使在此中,您也有与 等待 ,例如时间,最大消息数和过滤器。例子:

const filter = (click) =. {
    // Do some validation
}
const collector = message.channel.createMessageComponentCollector({
    time: '', // The time the collector is valid for in milliseconds
    max: '', // The number of messages the collector will wait for
    filter
})
collector.on('collect', i => console.log(i));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));

If you just want to wait for some messages to come, you can use awaitMessages. It has a few options such as the number of messages to wait for, the time it will collect messages for and an optional filter. An example:

const filter = (message) => {
    // Do some validation
}
message.channel.awaitMessages({
    time: '', // The time the collector is valid for in milliseconds
    max: '', // The number of messages the collector will wait for
    filter,
    error: ['time'] // Give an error when the timer runs out so the .catch function runs
}).then(collected => console.log(collected)) // Console log all the collected messages
.catch(collected => console.log(`${collected.size} messages were collected`))

But if you are using buttons, then a simple messageComponentCollector will do. Even in this, you have the same options as the awaitMessages such as the time, the maximum number of messages and the filter. Example:

const filter = (click) =. {
    // Do some validation
}
const collector = message.channel.createMessageComponentCollector({
    time: '', // The time the collector is valid for in milliseconds
    max: '', // The number of messages the collector will wait for
    filter
})
collector.on('collect', i => console.log(i));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文