You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.js v12移除用户所有角色报错[INVALID_TYPE]问题排查

解决Discord机器人角色操作的INVALID_TYPE错误

Hey there, let's break down why you're hitting that [INVALID_TYPE] error and how to fix it—you were right to suspect that line of code!

错误根源

The problem is in member.roles.remove(member.roles).

member.roles isn't a list of roles you can pass directly to the remove() method—it's a GuildMemberRoleManager object that handles the member's role management, not the actual role data. The remove() method expects an array/Collection of role objects, role IDs (snowflakes), or a single role/ID. Passing the manager object here causes the type mismatch error you're seeing.

修复方法

To remove all of the member's roles, you need to grab the actual collection of roles first, then pass that (or their IDs) to remove(). Here are two clean ways to do this:

方法1:提取角色ID数组

Use member.roles.cache.map(role => role.id) to get an array of role snowflakes, which the remove() method accepts perfectly:

member.roles.remove(member.roles.cache.map(role => role.id))
  .catch(error => console.log(error));

方法2:直接传入角色缓存集合

Since member.roles.cache is a Collection of role objects, you can pass that directly to remove() too:

member.roles.remove(member.roles.cache)
  .catch(error => console.log(error));

额外提醒

  • Double-check that your bot has the MANAGE_ROLES permission in the server, and that its highest role is positioned higher than any roles you're trying to remove (otherwise you'll run into permission errors instead).
  • Don't worry about the default "@everyone" role—Discord automatically prevents removing it, so you don't need to add extra logic to skip it.

内容的提问来源于stack exchange,提问作者Pandicon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 08:22:54