计数频道discord.js v14

问题描述 投票:0回答:1
if (counterChannel && counterChannel.type === "GUILD_VOICE") {
    const currentName = counterChannel.name;
    const match = currentName.match(/^vouches-(\d+)$/);
    if (match) {
        const currentCount = parseInt(match[1]);
        const newCount = currentCount + 1;
        const newName = `vouches-${newCount}`;

        await counterChannel.setName(newName);
        console.log(`The counter channel's new name is ${newName}`);
    } else {
        console.error("Counter channel name format is invalid.");
    }
} else {
    console.error("Counter channel not found or is not a voice channel.");
}

我正在制作一个 Discord 机器人。它有一个 /vouch 命令,每次执行时计数器都应该增加 1,因此对于计数系统,我使用的是语音通道,每次都应该重命名,并且数字应该增加 1。

是的,所以它不太有效。

javascript node.js discord discord.js
1个回答
0
投票

请提供有关您的程序如何无法运行的更多信息。尽管如此,我会提供一些途径供您探索以尝试解决问题。

您是否启用了适当的意图?您将需要

GUILDS
意图来更新语音通道。请参阅此处。您还需要在开发者门户和 Discord 服务器中适当定义机器人的权限。在这种情况下,您需要为您的机器人启用
Manage Channels
权限(在 OAuth2 页面下列出),然后重新邀请该机器人到您的 Discord 服务器。

另请注意,Discord 重命名频道的速率限制为每十分钟两次。

© www.soinside.com 2019 - 2024. All rights reserved.