Discord.js:message.guild.channels.forEach 不是函数

时间:2023-02-10
本文介绍了Discord.js:message.guild.channels.forEach 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Discord.js 创建一个 Discord 机器人

I'm creating a Discord Bot using Discord.js

我正在创建静音命令,但当我想为每个频道禁用静音角色的发言权限时,我收到此错误:

I'm creating a mute command but when I want to disable speaking permission for the Mute role for each channel, I get this error:

TypeError: message.guild.channels.forEach is not a function

我有 V12.我查看了其他一些选项,但找不到任何可行的选项.

I have V12. And I looked at some other options but I couldn't find any working options.

  if(!toMute) return message.reply('It looks like you didnt specify the user!');
  if(toMute.hasPermission('MANAGE_MESSAGES')) return message.reply("can't mute them");
  let muterole = message.guild.roles.cache.find(r => r.name === 'muted');
  if(!muterole){
    try{
      muterole = await message.guild.roles.create({
        name: "muted",
        color: "#000000",
        permissions: []
      })
      message.guild.channels.forEach(async (channel, id) => {
        await channel.overwritePermission(muterole, {
          SEND_MESSAGES: false,
          ADD_REACTIONS: false
        });
      });
    }catch(e){
      console.log(e.stack);
    }
  } return message.channel.send('Cant')


  let mutetime = args[1];
  if(!mutetime) return message.reply('You didnt specify the time');

  await(toMute.addRole(muterole.id));
  message.reply(`Successfully muted <@${toMute.id}> for ${ms(mutetime)}`);

  setTimeout(function(){
    toMute.removeRole(muterole.id);
    message.channel.send(`<@${toMute.id}> has been unmuted!`);
  }, ms(mutetime));

}

推荐答案

请尝试

message.guild.channels.cache.forEach((channel)=>{
 ...
})

参考:https://discord.js.org/#/docs/main/stable/class/GuildChannelManager?scrollTo=cache

这篇关于Discord.js:message.guild.channels.forEach 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:无法读取未定义的属性“fetchBans" 下一篇:TypeError: message.guild.channels.find(...).then 不是函数

相关文章

最新文章