自动更改频道名称不会重复(>=10m)(discord.js v12)

egmofgnx  于 2021-09-23  发布在  Java
关注(0)|答案(1)|浏览(299)

下面是我改进的所有代码https://github.com/favianrizqulloh/discord-clock 这样它可以在更多的频道上使用,但是在一些 updateinterval 时间(>=10m)不重复重命名过程(我使用600000ms)。因此,命令没有重复。请帮帮我!

//Import some packages needed
const moment = require('moment');
const tz = require('moment-timezone');
const chalk = require('chalk');
const Discord = require('discord.js');
const client = new Discord.Client();

module.exports = {
    name: "time",
    desciption: "Update time",
    async run (client, message, args) {
        console.log(`${message.createdAt} | ${message.author.tag} ${message.author} : ${message}`)
        // />time timezone format clockchannel updateinterval
        //clockchannel: // ID of a voice channel that used to display the time
        //timezone:  // Timezone (take a look at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List, add '(z) in last to show GMT)
        //format:  // Clock format, leave this default seting for 24h format, read more at https://momentjs.com/docs/#/displaying/format/
        //updateinterval // Discord is ratelimiting us for 10 minutes!
        //[ON WORK, IGNORE THIS FIELD] dev: '400581909912223744', // Developer's ID for sending the errors
        const timezone = args[0]
        const format = args[1]
        const clockchannel = args[2]
        const updateinterval = args[3]
        if (updateinterval < 600000) {message.channel.send('LỖI : KHOẢNG CÁCH UPDATE PHẢI KHÔNG NHỎ HƠN 600000ms')}
        else {
            message.channel.send('THIẾT ĐẶT THÀNH CÔNG');
            //init time
            const timeNow = moment().tz(timezone).format(format);
            //define clockChannel
            const clockChannel = client.channels.cache.get(clockchannel);
            //initial update
            clockChannel.edit({ name: `🕒 ${timeNow}` },'UPDATED')
                .catch(console.error);
            //set the interval
            setInterval(() => {
                const timeNowUpdate = moment().tz(timezone).format(format);
                clockChannel.edit({ name: `🕒 ${timeNow}` },'UPDATED')
                    .catch(console.error);
            }, updateinterval);
        }
    }
}
rjee0c15

rjee0c151#

好的,我从discord时钟程序中修复了一些代码,它成功了。我将把代码放在下面:

//Import some packages needed
const moment = require('moment');
const tz = require('moment-timezone');
const chalk = require('chalk');
const Discord = require('discord.js');
const client = new Discord.Client();

module.exports = {
    name: "time",
    desciption: "Update time",
    async run (client, message, args) {
        console.log(`${message.createdAt} | ${message.author.tag} ${message.author} : ${message}`)
        // />time timezone format clockchannel updateinterval
        //clockchannel: // ID of a voice channel that used to display the time
        //timezone:  // Timezone (take a look at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List, add '(z) in last to show GMT)
        //format:  // Clock format, leave this default seting for 24h format, read more at https://momentjs.com/docs/#/displaying/format/
        //updateinterval // Discord is ratelimiting us for 10 minutes!
        //[ON WORK, IGNORE THIS FIELD] dev: '400581909912223744', // Developer's ID for sending the errors
        const timezone = args[0]
        const format = args[1]
        const clockchannel = args[2]
        const updateinterval = args[3]
        if (updateinterval < 600000) {message.channel.send('LỖI : KHOẢNG CÁCH UPDATE PHẢI KHÔNG NHỎ HƠN 600000ms')}
        else {
            message.channel.send('THIẾT ĐẶT THÀNH CÔNG');
            //init time
            let timeNow = moment().tz(timezone).format(format);
            //define clockChannel
            const clockChannel = client.channels.cache.get(clockchannel);
            //initial update
            clockChannel.edit({ name: `🕒 ${timeNow}` },'UPDATED')
                .catch(console.error);
            //set the interval
            setInterval(function() {
                let timeNow = moment().tz(timezone).format(format);
                clockChannel.edit({ name: `🕒 ${timeNow}` },'UPDATED')
                    .catch(console.error);
            }, updateinterval);
        }
    }
}

相关问题