Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除服务器| Discord.js中的所有角色_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript 删除服务器| Discord.js中的所有角色

Javascript 删除服务器| Discord.js中的所有角色,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我正在尝试使用discord bot删除服务器的所有角色。但它出现了这个错误: (node:10096) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Role at RequestHandler.execute (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\amy nuker\node_modules\discord.js\s

我正在尝试使用discord bot删除服务器的所有角色。但它出现了这个错误:

(node:10096) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Role
    at RequestHandler.execute (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\amy nuker\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:10096) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10096) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我的代码:

        if(message.content.startsWith(prefix + 'roled')){

        message.guild.roles.cache.forEach(roles => roles.delete());

        }
这不起作用,所以我尝试使用.map()功能

        if(message.content.startsWith(prefix + 'roled')){
        //  message.guild.roles.cache.map(roles => roles.delete());
        }

但是没有用。我还是犯了和以前一样的错误。如何解决此问题?

据我所知。delete()返回一个承诺,因此您需要使用
async/wait
then/catch

message.guild.roles.cache.forEach(roles => {
    roles.delete()
    .then(deleted => console.log(`Deleted role ${deleted.name}`))
    .catch(console.error);
});

根据我的理解,在中找到。delete()返回一个承诺,因此您需要使用
async/wait
then/catch

message.guild.roles.cache.forEach(roles => {
    roles.delete()
    .then(deleted => console.log(`Deleted role ${deleted.name}`))
    .catch(console.error);
});

中发现,承诺不需要履行。承诺不需要履行。