admin管理员组文章数量:1405381
I am trying to make a mand, where I can get every guild invite that the bot is currently in. Current code:
client.on('message', async (message) => {
if (message.content.startsWith(prefix + 'invite')) {
let invite = client.guilds
.createInvite({
maxAge: 0, // 0 = infinite expiration
maxUses: 0, // 0 = infinite uses
})
.catch(console.error);
message.channel.send(invite);
}
});
Error:
DiscordAPIError: Cannot send an empty message
I am trying to make a mand, where I can get every guild invite that the bot is currently in. Current code:
client.on('message', async (message) => {
if (message.content.startsWith(prefix + 'invite')) {
let invite = client.guilds
.createInvite({
maxAge: 0, // 0 = infinite expiration
maxUses: 0, // 0 = infinite uses
})
.catch(console.error);
message.channel.send(invite);
}
});
Error:
DiscordAPIError: Cannot send an empty message
Share
Improve this question
edited Sep 22, 2020 at 16:06
Lioness100
8,4226 gold badges20 silver badges50 bronze badges
asked Aug 22, 2020 at 13:51
MedrajMedraj
1732 gold badges6 silver badges17 bronze badges
1
- Note that Discord allows bots to create invites to guild only when they are allowed to, ie. a guild administrator does a mand to create a new invite. Creating invites without permission from the guild's moderators/admins isn't allowed – Diamond Commented Aug 22, 2020 at 16:29
1 Answer
Reset to default 6Try this:
var invites = []; // starting array
message.client.guilds.cache.forEach(async (guild) => { // iterate loop on each guild bot is in
// get the first channel that appears from that discord, because
// `.createInvite()` is a method for a channel, not a guild.
const channel = guild.channels.cache
.filter((channel) => channel.type === 'text')
.first();
if (!channel || guild.member(client.user).hasPermission('CREATE_INSTANT_INVITE') return;
await channel
.createInvite({ maxAge: 0, maxUses: 0 })
.then(async (invite) => {
invites.push(`${guild.name} - ${invite.url}`); // push invite link and guild name to array
})
.catch((error) => console.log(error));
console.log(invites);
});
As an example, this is what I got after running the mand:
GuildChannel.createInvite()
Array.prototype.forEach()
本文标签: javascriptDiscordjs how can I create an invite for every guild my bot is inStack Overflow
版权声明:本文标题:javascript - Discord.js how can I create an invite for every guild my bot is in? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744321568a2600524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论