Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

javascript - Showing error during using overwritepermission

I was expecting to give everyone 10 sec to type and then remove the permission but the script is not working.

if (message.channel.id === "channel id") {
    if (!message.member.roles.cache.has("everyone's id")) {
        setInterval(function () { 
            message.channel.send("start").then(channel => {
                channel.overwritePermissions([{
                    id: message.guild.id,
                    allow: 0x00000800
                }]).then(channel => {
                    setTimeout(function () {
                        channel.overwritePermissions([{
                            id: message.guild.id,
                            deny: 0x00000800
                        }])                        
                    }, 10000);
                });   
            })
        }, 5000);
    }
}

This error is showing in the terminal.

(node:14500) UnhandledPromiseRejectionWarning: TypeError: channel.overwritePermissions is not a function
    at C:UsersAdminDesktopDiscord botBOT SHOTcommands
epeat1.js:9:29
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14500) 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:14500) [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.```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The channel.send() function returns a Message not a Channel. The correct code would be:

.then(() => {
    message.channel.overwritePermissions([
    {
      id: message.guild.id,
      allow: [0x00000800]
    },
])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...