【问题标题】:How can I check if someone is in a voice channel in DiscordJS V13?如何在 DiscordJS V13 中检查某人是否在语音频道中?
【发布时间】:2021-11-03 20:17:23
【问题描述】:

我正在尝试检查发起命令的用户当前是否在语音频道中,并且在我运行机器人后,我的代码正常工作,如果我随后离开频道并重新获得语音频道信息,启动命令我要返回与缓存相同的语音通道信息?接收最新信息的唯一方法是完全重启我的机器人。

export const interactionListener = async (interaction, client) => {
  if (!interaction.isCommand()) return; 
  const { commandName } = interaction; 
  switch (commandName) {
    case 'play':
      let user = await interaction.member.fetch();
      let channel = await user.voice.channel;
      if (!channel) {
        interaction.reply('you are not in a voice channel');
      } else {
        interaction.channel.send('do something else');
      }
 }
};

并且该代码运行在一个interactionCreate here上

client.on('interactionCreate', async (interaction) => {
  interactionListener(interaction, client);
});

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    已修复:我需要另一个意图

    之前的意图是:

    const client = new Client({
      intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_PRESENCES,
      ],
    });
    

    新的意图是:

    const client = new Client({
      intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_PRESENCES,
        Intents.FLAGS.GUILD_VOICE_STATES,
      ],
    });
    

    我不见了

    Intents.FLAGS.GUILD_VOICE_STATES
    

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 2022-01-11
      • 1970-01-01
      • 2021-11-21
      • 2021-04-13
      • 1970-01-01
      • 2021-08-18
      • 2021-03-30
      • 2021-07-05
      相关资源
      最近更新 更多