Discord.js 是一个用于与 Discord API 交互的 Node.js 库。要让 Discord.js 读取回复(reply),你需要使用 MessageCollector 类来收集消息。以下是一个简单的示例代码:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'readreply') {
const { channel } = interaction;
// 创建一个消息收集器
const collector = new client.MessageCollector(channel, m => m.author.id === interaction.user.id, { time: 15000 });
collector.on('collect', message => {
console.log(`Collected ${message.content}`);
// 在这里处理收集到的消息
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} messages`);
});
await interaction.reply('请在接下来15秒内回复消息。');
}
});
client.login('YOUR_BOT_TOKEN');
time
参数以满足你的需求。通过以上步骤和代码示例,你应该能够成功实现 Discord.js 读取回复的功能。
领取专属 10元无门槛券
手把手带您无忧上云