【问题标题】:Is there any way to get a bot to create a guild on Discord?有没有办法让机器人在 Discord 上创建公会?
【发布时间】:2021-01-12 02:49:41
【问题描述】:

我正在使用 discord.js V12,我正在尝试让我的机器人创建一个公会,其中包含一个频道。但是,我无法修复此错误“TypeError:channels is not iterable”。这是我当前的代码:

client.on("message", async message => {
    if(message.content == "?createGuild") {
        let guild = await client.guilds.create("Test Guild", {channels: {id: 1, type: "text", name: "invite-channel"}}).catch(err => {console.log(err)});        
        let guildchannel = await guild.channels.find(cha => cha.name == "invite-channel");
        let invite = await guildchannel.createInvite({maxAge: 0, unique: true, reason: "Testing."});
        message.channel.send(`https://discord.gg/${invite.code} is the server I created!`);
    }
});

谁能帮帮我?

【问题讨论】:

  • 欢迎来到 Stack Overflow。请按照建议添加您的搜索/研究工作的简短描述、代码、错误。

标签: node.js discord discord.js


【解决方案1】:

Client.guilds.create 将选项Object 作为第二个参数。 Options.channels 采用Array,包含多个对象,每个对象代表一个通道。您改为提供Object

请注意,每个人都可以创建公会,因为您对此命令没有任何限制。


client.on("message", async message => {
    if (message.content == "?createGuild") {
        const Guild = await client.guilds.create("Test Guild", {
            channels: [
                {"name": "invite-channel"},
            ]
        });

        const GuildChannel = Guild.channels.cache.find(channel => channel.name == "invite-channel");
        const Invite = await GuildChannel.createInvite({maxAge: 0, unique: true, reason: "Testing."});
        message.channel.send(`Created guild. Here's the invite code: ${Invite.url}`);
    };
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-01
    • 2022-12-12
    • 1970-01-01
    • 2020-12-27
    • 2021-03-29
    • 2021-06-24
    • 2021-04-21
    • 2021-05-25
    相关资源
    最近更新 更多