56 Replies
Creating a giveaway command
with djs and sapphirejs
so I do the command for example
/giveaway prize: 1 winners: 3 duration: 1m
then it would https://gyazo.com/7f489eb461275b0d452dd17e8958c59a
Gyazo
Gyazo
1m is 1 minute
this shit is making 1 hour from it
duration: 1mthat's a string yet you call
const durationHours = parseInt(duration, 10);
?If you use @sapphire/duration, it has a "Duration" class that will get the right values for you from human readable stuff
That's the easy way around it imo
yeah should be something like this wherein
paramater
is the argument provided
that's what we do for @Skyra as well
I think your problem is that you're parsing 1m
as if it doesn't include that m
for an indicator of time unit
actually looking at your messageRun
method you did implement the splitting of time unit and number value there but you didn't do that for chatInputRunI dont understand what the difference is for messagerun and chatinputrun
one is for message based commands and the other is for slash commands
message based commands being the old thing that we did before slash commands
i.e.
!giveaway whatever
Would this work then
reduced to a bare minimum to save on characters, sample from it as you would
And btw , @Favna how would I trigger the end of a giveaway?
Never did such thing
store a reference (probably to the message people react to) somewhere, like in a database, and upon people executing
/giveaway-end
or a timer expiring stop collecting reactions and/or delete the messageI do save it in a db
const giveaway = await prisma.giveaway.create({
data: {
guildId: interaction.guildId!,
channelId: interaction.channelId!,
messageId: reply.id,
endsAt,
prize,
winners,
roles: rolesString,
invites: invitesString
},
});
so I did task/endGiveaway.ts with this
but it aint working
@Skyra used to have a giveaway module so you can dig through the git history if you want but we removed it because we came to the realization that we didn't want to bother competiting with Giveaway Bot which any large server is going to invite anyway because it had better features than our module
https://github.com/skyra-project/skyra if you want to give it a shot
GitHub
GitHub - skyra-project/skyra: A multipurpose Discord Bot designed t...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
cant find it rip
3000 commits
GitHub
skyra/src/commands/Giveaway at ea0779809291c9708f1050ff87e666b3337f...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
skyra uses a own lib too
no? wdym?
import { LanguageKeys } from '#lib/i18n/languageKeys';
import { SkyraCommand } from '#lib/structures';
import type { GuildMessage } from '#lib/types';
import { Schedules } from '#lib/types/Enums';
those are NodeJS subpath imports
the second one is https://github.com/skyra-project/skyra/blob/ea0779809291c9708f1050ff87e666b3337f3101/src/lib/structures/commands/SkyraCommand.ts
GitHub
skyra/src/lib/structures/commands/SkyraCommand.ts at ea0779809291c9...
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
it is outdated code tho
this is Sapphire v2
Ill just make my own simple giveaway command
worse.. v1 I think
everything except the actual giveaway ending works
oh no it is v2 but a very early stage of v2
can you use setInterval?
for things like this
you can but setInterval depends on process cycles so will desync if the giveaway runs for too long (i.e. a day or more)
whats a better way?
node-cron?
@sapphire/plugin-scheduled-tasks
damn
which uses BullMQ which in turn uses Redis
sapphire has everything
https://sapphirejs.dev/docs/Documentation/api-plugins/modules/sapphire_plugin_scheduled_tasks/
not found
uh
old link
found
where did you get that?
needs to be updated
google
oh
this one works
google you silly boy
yeah I recently updated the website so it uses new doc gen stuff
now the url is proper
but why redis etc
I want to host 1 single thing and thats the bot xd
as an example I use this plugin for @Dragonite to periodically dump stats to InfluxDB
because it uses https://docs.bullmq.io
What is BullMQ | BullMQ
General description of BullMQ and its features
do I need to host another serve rthenm
what do you host your bot on rn
pterodactyl
and just localhost when dev
no idea how that works then. Never used it
ill stick with nodecron then ig
Pterodactylยฎ is a free, open-source game server managementThis concerns me though something about fitting a square peg in a round hole by using it for a bot
its just a docker management system
like portainer
but normally designed for games indeed
well you'd run Redis as a Docker container too but sounds like you're not really familiar with hosting infrastructure yet so take it slow and learn as you go
btw you will need to host that database you use Prisma for somewhere ๐
I know
So I got this from gpt as I dont know what the heck cron schedule is
but it couldnt find the client. Made it in src/Scheduler.ts
https://crontab.guru is your friend
Crontab.guru - The cron schedule expression generator
An easy to use editor for crontab schedules.
Sapphire Framework
Accessing the Client | Sapphire
Often when writing your [listeners], [commands], [preconditions], [arguments] and other pieces you will want to access