如何返回公会的所有者名称 [英] How to return a guild's owner name

查看:58
本文介绍了如何返回公会的所有者名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我遇到问题的代码片段:

This is the piece of my code where I'm having the problem:

const guild = client.guilds.get('500170876243935247');
message.channel.send(guild.owner);

我希望它返回所有者的名字,相反,它在控制台中说这是一条空消息.我已经运行了 guild.owner console.log ,显然它显示的是来自行会的所有数据,表情符号,会员ID,最后显示了所有者的用户详细信息,操作方式我要分别显示它们吗?

I expected it to return the owner's name, instead it says in the console that it's an empty message. I've run guild.owner with console.log and apparently it's displaying all data from the guild, emojis, member's IDs and at the end, the owner's user details, how do I display them separately?

记录下来,这是我认为需要重点关注的最后一部分:

For the record, this is the last part that I think is the focus that I need:

user:
 User {
  id: '317669302549XXXXXX',
  username: 'Flicker',
  discriminator: 'XXXX',
  avatar: 'a_161cc6f5d0466f7afd9a73dc2eba159d',
  bot: false,
  lastMessageID: null,
  lastMessage: null },
 joinedTimestamp: 1539320429681,

推荐答案

将用户转换为字符串时, User.toString() ,因此discord.js将留有无法发送的对象(有效对象的示例: message.channel.send( RichEmbed )),因此邮件为空.

When you convert a User to a string, the 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)), and so the message will be empty.

为避免这种情况,您可以尝试使用 User.tag :这样,您还可以避免每次有人使用该命令时都收到通知.
如果您不介意收到通知,则可以在可能的情况下使用第一个,否则可以使用第二个.这是一个示例:

To avoid this, you can try to replace the mention with something like User.tag: with this you also avoid being notified every time someone uses that command.
If you don't mind being notified you can use the first one when possible, otherwise the second one. Here's an example:

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

这篇关于如何返回公会的所有者名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆