📅  最后修改于: 2023-12-03 15:00:25.749000             🧑  作者: Mango
使用discord.js可以很方便地获取到Discord用户的用户名,以下是具体的实现方法。
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
其中,tag
可以获取到用户的用户名和后缀标识,例如John#1234
。
user.id
获取到用户的唯一标识ID:const user = message.author;
console.log(`${user.username} 的ID为:${user.id}`);
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
const user = message.author;
console.log(`${user.username} 的ID为:${user.id}`);
});
client.login('your-token-goes-here');
```javascript
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
const user = message.author;
console.log(`${user.username} 的ID为:${user.id}`);
});
client.login('your-token-goes-here');