在Discord.js中,私信(DM)是用户之间一对一沟通的方式。要在Discord.js的DM中收集用户信息,你需要遵循以下步骤:
以下是一个简单的示例,展示如何在Discord.js中收集用户信息:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (message.content === '!start') {
await message.author.send('Hello! Please provide your name and email:');
} else if (message.channel.type === 'dm') {
const userInfo = message.content.split(',').map(info => info.trim());
if (userInfo.length === 2) {
const [name, email] = userInfo;
console.log(`Collected user info: Name - ${name}, Email - ${email}`);
await message.author.send('Thank you for providing your information!');
} else {
await message.author.send('Invalid format. Please provide your name and email separated by a comma.');
}
}
});
client.login('YOUR_BOT_TOKEN');
通过以上步骤和示例代码,你可以在Discord.js的DM中有效地收集用户信息。
领取专属 10元无门槛券
手把手带您无忧上云