Open MatteoBax opened 2 years ago
What command is causing this error? Please provide all the code in that command aswell. I presume your talking about wok commands version 1.2.8 aswell, may I ask why you dont use the latest version?
Yes, the version of wokcommands is 1.2.8 I don't update it because if I update it the command no longer works.
const allowedusers = [
"530079936766279680",
"621362828049383424",
"433693486156611585",
]
const momentTimezone = require('moment-timezone')
const { MessageCollector } = require('discord.js')
const scheduledSchema = require('../models/scheduled-schema')
module.exports = {
requiredPermissions: ['ADMINISTRATOR'],
expectedArgs: '<Channel tag> <YYYY/MM/DD> <HH:MM> <"AM" or "PM"> <Timezone>',
minArgs: 5,
maxArgs: 5,
init: (client) => {
const checkForPosts = async () => {
const query = {
date: {
$lte: Date.now(),
},
}
const results = await scheduledSchema.find(query)
for (const post of results) {
const { guildId, channelId, content } = post
const guild = await client.guilds.fetch(guildId)
if (!guild) {
continue
}
const channel = guild.channels.cache.get(channelId)
if (!channel) {
continue
}
channel.send(content)
}
await scheduledSchema.deleteMany(query)
setTimeout(checkForPosts, 1000 * 10)
}
checkForPosts()
},
callback: async ({ message, args }) => {
const { mentions, guild, channel } = message
const targetChannel = mentions.channels.first()
if (!targetChannel) {
message.reply('Please tag a channel to send your message in.')
return
}
// Remve the channel tag from the args array
args.shift()
const [date, time, clockType, timeZone] = args
if (clockType !== 'AM' && clockType !== 'PM') {
message.reply(
`You must provide either "AM" or "PM", you provided "${clockType}"`
)
return
}
const validTimeZones = momentTimezone.tz.names()
if (!validTimeZones.includes(timeZone)) {
message.reply(
'Unknown timezone! Please use one of the following: <https://gist.github.com/AlexzanderFlores/d511a7c7e97b4c3ae60cb6e562f78300>'
)
return
}
const targetDate = momentTimezone.tz(
`${date} ${time} ${clockType}`,
'YYYY-MM-DD HH:mm A',
timeZone
)
message.reply('Please send the message you would like to schedule.')
const filter = (newMessage) => {
return newMessage.author.id === message.author.id
}
const collector = new MessageCollector(channel, filter, {
max: 1,
time: 1000 * 60, // 60 seconds
})
collector.on('end', async (collected) => {
const collectedMessage = collected.first()
if (!collectedMessage) {
message.reply('You did not reply in time.')
return
}
message.reply('Your message has been scheduled.')
await new scheduledSchema({
date: targetDate.valueOf(),
content: collectedMessage.content,
guildId: guild.id,
channelId: targetChannel.id,
}).save()
})
},
}
So how can I fix it?
Can anyone help me please?
I am looking over your code and maybe I can say about it.
Small side note though:
message.reply('You must provide either "AM" or "PM", you provided "${clockType}"' )
I would think about abuse here: if this is a public bot users could enter bad words and the bot would display them. Could theoretically be that your bot is banned in servers with automoderation because of this.
EDIT: I don't get how to escape a ` so i replaced them with '
Thanks for the answer but it crashes anyway and gives the same error
Can anyone help me please?
Can anyone help me please?
Hi, I have a problem for some time wokcommands from this error when I run the command. It is always gone, it has been giving me this error for about 1 month. I have not changed the code of the command so I would like to know if it is possible to fix. The version in question is 1.2.8
Error: