【问题标题】:Is there a way I can join a discord server, through its ID, My bot is already in the server [duplicate]有没有办法可以通过其 ID 加入不和谐服务器,我的机器人已经在服务器中 [重复]
【发布时间】:2021-01-10 06:10:42
【问题描述】:

我的机器人在一些我不在的服务器中,我想在我的机器人的帮助下加入这些服务器。

我尝试了很多不同的代码,但似乎没有一个适合我。我发现了一个与我相似的问题,但它是针对 discord.py (python)。

我的机器人是用 Discord.JS 编码的。 H 我希望能够执行 +create (ID),然后返回该服务器邀请链接。

例如:+创建 2320329132 |返回:discord.gg/Ud9283

对不起,我的英语不好。谢谢你,如果你能帮助我:)

【问题讨论】:

标签: discord discord.js


【解决方案1】:
let guild = client.guilds.cache.get(args[0]);
let channel = guild.channels.cache.filter(ch => ch.type === "text");
channel.first().createInvite({ maxUsers: 1, maxAge: 0, unique: true})
.then(invite => message.channel.send(`https://discord.gg/${invite.code}`));

我假设您已经定义了 args 和 client。 guild 存储您通过其 ID 提供的服务器。 channel 过滤每个文本通道并将其存储。然后我们使用channel.first() 获取第一个找到的文本频道,并使用.createInvite() 创建邀请(因为您只能创建频道的邀请)。之后我们使用.then获取邀请码并将完整链接发送到当前文本频道。

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 2019-06-13
    • 2019-08-28
    • 2019-10-29
    • 2021-08-26
    • 2021-03-21
    • 2021-06-24
    • 2020-07-21
    • 2021-08-10
    相关资源
    最近更新 更多