检查用户是否具有x个角色之一,然后从他们中删除该角色

时间:2020-07-30 22:53:52

标签: javascript discord roles

我正在尝试构建一个函数,该函数将允许我检查Discord服务器中的所有成员以查看它们是否属于某个角色集中,然后从其中删除该角色。

        function StripRoles(){ //will get the players who still have roles assigned to them, and remove those roles
        const RolesArray = ['737531569165565982','737533396422754355','737533710798290974','737532883539066971','737533050925350932','737533864544567296','737534067188301854']; //here's the list of roles
        var i;
        for (i = 0; i < RolesArray.length; i++) { //loop that checks each of the roles in RolesArray
            message.guild.members.cache.forEach(member => { //for each member of the server
                if (member.roles.has(RolesArray[i])){ //if they have the role currently being checked
                    member.roles.remove(i).catch(console.error); //then remove it from them
                }
           })
        }
    }

当我运行它时,它返回错误:

TypeError: member.roles.has is not a function

任何帮助将不胜感激!

编辑:为我自己的新手参考添加了更多标签

2 个答案:

答案 0 :(得分:1)

您可以使用(function(){ 'use strict'; angular.module('utilsModule') .factory('timeoutFactory', timeoutFactory); timeoutFactory.inject = ['$q', '$injector', '$log', '$timeout']; function timeoutFactory($q, $injector, $log, $timeout) { /* jshint validthis: true */ var vm = this; var opened = false; return { request: timeoutError }; function timeoutError(config) { var deferred = $q.defer(); config.timeout = deferred.promise; $timeout(function() { deferred.resolve(); // this aborts the request! }, 100); // 1 minute or 60 seconds or 60,000 milliseconds return config; } } })(); myFactory.myAPI(data) .then(function(response) { // response.status -1 here. }, function(error) { // no timeout response here. }); config: timeout: Promise $$state: pending: undefined processScheduled: false status: 1 value: undefined

.includes

编辑:要帮助调试,可以执行以下操作:

if (member.roles.includes(RolesArray[i])){

告诉我它记录了什么?

好吧,看着discords docs,我认为,您只需要这样做:

for (i = 0; i < RolesArray.length; i++) { //loop that checks each of the roles in RolesArray
    message.guild.members.cache.forEach(member => { //for each member of the server
        console.log({
            roles: member.roles,
            type: typeof member.roles,
            array: Array.isArray(member.roles)
        });
    })
}

答案 1 :(得分:0)

如果With Query1 As ( Select staging.dbo.manualdata_DateDimension.Year, staging.dbo.manualdata_DateDimension.FortnightofYear, Min(staging.dbo.manualdata_DateDimension.Date) As min_date, Max(staging.dbo.manualdata_DateDimension.Date) As max_date, Cast(DateAdd(Day, DateDiff(Day, 1, Min(staging.dbo.manualdata_DateDimension.Date)), 0) As date) As previous_fortnight_max_date From staging.dbo.manualdata_DateDimension Group By staging.dbo.manualdata_DateDimension.Year, staging.dbo.manualdata_DateDimension.FortnightofYear Having @rundate Between Min(staging.dbo.manualdata_DateDimension.Date) And Max(staging.dbo.manualdata_DateDimension.Date) ) Select Query1.Year, Query1.FortnightofYear, Query1.min_date, Query1.max_date, Query1.previous_fortnight_max_date, staging.dbo.manualdata_DateDimension.FortnightofYear As PreviousFortnightofYear From Query1 Inner Join staging.dbo.manualdata_DateDimension On staging.dbo.manualdata_DateDimension.Date = Query1.previous_fortnight_max_date 是列表,请使用includes代替has