如何 return 公会的所有者名称
How to return a guild's owner name
这是我遇到问题的代码片段:
const guild = client.guilds.get('500170876243935247');
message.channel.send(guild.owner);
我原以为它是 return 所有者的名字,但它在控制台中说这是一条空消息。我有 运行 guild.owner
和 console.log
,显然它显示了公会的所有数据、表情符号、成员 ID,最后是所有者的用户详细信息,我如何分别显示它们?
郑重声明,这是我认为需要重点关注的最后一部分:
user:
User {
id: '317669302549XXXXXX',
username: 'Flicker',
discriminator: 'XXXX',
avatar: 'a_161cc6f5d0466f7afd9a73dc2eba159d',
bot: false,
lastMessageID: null,
lastMessage: null },
joinedTimestamp: 1539320429681,
当您将 User 转换为字符串时,User.toString()
method is automatically called: that converts the User object into a mention, like @username. But if you do message.channel.send(User)
it will not call User.toString()
and so discord.js will be left with an object that it can't send (example for valid object: message.channel.send(
RichEmbed
)
),因此消息将为空。
为避免这种情况,您可以尝试用 User.tag
之类的内容替换提及:这样您还可以避免每次有人使用该命令时都收到通知。
如果您不介意收到通知,您可以尽可能使用第一个,否则使用第二个。这是一个例子:
const guild = client.guilds.get('500170876243935247');
message.channel.send(message.guild.member(guild.owner) ? guild.owner.toString() : guild.owner.user.tag);
// if the user is in that guild it will mention him, otherwise it will use .tag
client.on('message', msg => {
const thisguild = msg.guild;
const owner = thisguild.owner.user.username;
}
Discordjs v11.5.1
在这些示例中,Guild
是您获得公会的位置的占位符。这可以是 message.guild
或 member.guild
或只是 guild
,具体取决于事件。或者,您可以通过 ID 获取公会(请参阅下一节)并使用它!
// Get a User by ID
client.users.get("user id here");
// Returns <User>
或
// Get a Member by ID
message.guild.members.get("user ID here");
// Returns <Member>
来源:Github
我使用上述文档的方法是:
let guild = msg.guild.members.get('372452704297025537');
let admin = msg.guild.member(guild);
message.channel.send(admin.user)
.catch(err => console.error(err))
这是我遇到问题的代码片段:
const guild = client.guilds.get('500170876243935247');
message.channel.send(guild.owner);
我原以为它是 return 所有者的名字,但它在控制台中说这是一条空消息。我有 运行 guild.owner
和 console.log
,显然它显示了公会的所有数据、表情符号、成员 ID,最后是所有者的用户详细信息,我如何分别显示它们?
郑重声明,这是我认为需要重点关注的最后一部分:
user:
User {
id: '317669302549XXXXXX',
username: 'Flicker',
discriminator: 'XXXX',
avatar: 'a_161cc6f5d0466f7afd9a73dc2eba159d',
bot: false,
lastMessageID: null,
lastMessage: null },
joinedTimestamp: 1539320429681,
当您将 User 转换为字符串时,User.toString()
method is automatically called: that converts the User object into a mention, like @username. But if you do message.channel.send(User)
it will not call User.toString()
and so discord.js will be left with an object that it can't send (example for valid object: message.channel.send(
RichEmbed
)
),因此消息将为空。
为避免这种情况,您可以尝试用 User.tag
之类的内容替换提及:这样您还可以避免每次有人使用该命令时都收到通知。
如果您不介意收到通知,您可以尽可能使用第一个,否则使用第二个。这是一个例子:
const guild = client.guilds.get('500170876243935247');
message.channel.send(message.guild.member(guild.owner) ? guild.owner.toString() : guild.owner.user.tag);
// if the user is in that guild it will mention him, otherwise it will use .tag
client.on('message', msg => {
const thisguild = msg.guild;
const owner = thisguild.owner.user.username;
}
Discordjs v11.5.1
在这些示例中,Guild
是您获得公会的位置的占位符。这可以是 message.guild
或 member.guild
或只是 guild
,具体取决于事件。或者,您可以通过 ID 获取公会(请参阅下一节)并使用它!
// Get a User by ID
client.users.get("user id here");
// Returns <User>
或
// Get a Member by ID
message.guild.members.get("user ID here");
// Returns <Member>
来源:Github
我使用上述文档的方法是:
let guild = msg.guild.members.get('372452704297025537');
let admin = msg.guild.member(guild);
message.channel.send(admin.user)
.catch(err => console.error(err))