A slash command that pulls you 1 to 5 random tarot cards. Complete with meaning/keywords, definition articles, and card images. You can ask question. Reversed cards are optional.
/** SIMPLE TAROT SLASH COMMAND
by vibrantium#0953
Warning:
1. Make sure the slash command is titled "tarot"
2. The command has four OPTIONAL options: "question" (for tarot question input), "amount" (of tarot cards requested),
"reversals" (for possible "reversed"/upside down cards on results), & suit (to pick Major Arcana or Minor Arcana cards only)
3. Unless you know what you are doing, do NOT delete any of those four options from the code. I won't fix your code for you.
*/
// DEPENDENCIES - do NOT delete EVER
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios'); // to shorten card image link
const base64 = require (`base64-url`); // to embed card image link
// This is how your slash command registration should look like in your slash command builder:
/** await lib.discord.commands['@0.0.0'].create({
"guild_id": "YOUR-GUILD-ID", // replace with your guild ID serial number
"name": "tarot",
"description": "Pulls tarot card(s)",
"options": [
{
"type": 3,
"name": "question",
"description": "Specify your question or reading topic"
},
{
"type": 3,
"name": "amount",
"description": "How many cards do you want? Defaults to one card.",
"choices": [
{
"name": "1",
"value": "1"
},
{
"name": "2",
"value": "2"
},
{
"name": "3",
"value": "3"
},
{
"name": "4",
"value": "4"
},
{
"name": "5",
"value": "5"
}
]
},
{
"type": 3,
"name": "reversals",
"description": "Possible reversals in your results? Defaults to \"don't use\"",
"choices": [
{
"name": "use",
"value": "yes"
},
{
"name": "don't use",
"value": "no"
}
]
},
{
"type": 3,
"name": "suit",
"description": "Specify if you want to use major or minor arcana only",
"choices": [
{
"name": "major arcana only",
"value": "major"
},
{
"name": "minor arcana only",
"value": "minor"
}
]
}
]
}); */
// End of slash command registration.
// DELETE up to THIS point if you have manually registered your slash command
// I repeat, do NOT delete the dependencies (the ones called "lib" & "base64")
// ACTUAL CODE
// Do not delete anything below, this is what the bot will do to serve your result
// I like to use try-catch just so the bot won't type forever if something goes wrong
try {
// Telling the bot to reply to slash command invocation
await lib.discord.interactions['@1.0.1'].responses.create({
token: context.params.event.token,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE'
});
// Detecting options
let question = context.params.event.data.options.find(
(option) => option.name === 'question'
);
let amount = context.params.event.data.options.find(
(option) => option.name === 'amount'
);
let reversals = context.params.event.data.options.find(
(option) => option.name === 'reversals'
);
let suit = context.params.event.data.options.find(
(option) => option.name === 'suit'
);
// Random card chooser according to card amount requested
var cardAmount
if (!amount || !amount.value) {cardAmount = 1}
else {cardAmount = Number(amount.value)} // end of card amount detector
// Determine card number ranges according to suit selection
var end
var start
if (!suit || !suit.value)
{
console.log(`User didn't choose any suit`)
start = 0
end = 77}
else if (suit.value === `major`)
{console.log(`User chose majors only`)
start = 0
end = 21}
else {
console.log(`User chose minors only`)
start = 22
end = 77} // end of determine suit cards
// Card number drawing selecting
let numbers = [...Array(end - start + 1).keys()].map((x) => x + start);
let sort = numbers.sort(() => Math.random() - 0.5);
let randomCards = sort.slice(0, cardAmount);
console.log(`randomCards array looks like:`);
console.log(randomCards);
// Card Definitions Database
let names = [`The Fool`,`The Magician`,`The High Priestess`,`The Empress`,`The Emperor`,`The Hierophant`,`The Lovers`,`The Chariot`,
`Strength`,`The Hermit`,`The Wheel of Fortune`,`Justice`,`The Hanged Man`,`Death`,`Temperance`,`The Devil`,`The Tower`,`The Star`,
`The Moon`,`The Sun`,`Judgement`,`The World`,`Ace of Cups`,`Two of Cups`,`Three of Cups`,`Four of Cups`,`Five of Cups`,`Six of Cups`,
`Seven of Cups`,`Eight of Cups`,`Nine of Cups`,`Ten of Cups`,`Page of Cups`,`Knight of Cups`,`Queen of Cups`,`King of Cups`,`Ace of Wands`,
`Two of Wands`,`Three of Wands`,`Four of Wands`,`Five of Wands`,`Six of Wands`,`Seven of Wands`,`Eight of Wands`,`Nine of Wands`,`Ten of Wands`,
`Page of Wands`,`Knight of Wands`,`Queen of Wands`,`King of Wands`,`Ace of Swords`,`Two of Swords`,`Three of Swords`,`Four of Swords`,
`Five of Swords`,`Six of Swords`,`Seven of Swords`,`Eight of Swords`,`Nine of Swords`,`Ten of Swords`,`Page of Swords`,`Knight of Swords`,
`Queen of Swords`,`King of Swords`,`Ace of Pentacles`,`Two of Pentacles`,`Three of Pentacles`,`Four of Pentacles`,`Five of Pentacles`,
`Six of Pentacles`,`Seven of Pentacles`,`Eight of Pentacles`,`Nine of Pentacles`,`Ten of Pentacles`,`Page of Pentacles`,`Knight of Pentacles`,
`Queen of Pentacles`,`King of Pentacles`]
let Upright = [`innocence, new beginnings, free spirit.`,`willpower, desire, creation, manifestation`,
`intuitive, unconscious, inner voice.`,`motherhood, fertility, nature.`,`authority, structure, control, fatherhood.`,
`tradition, conformity, morality, ethics.`,`partnerships, duality, union.`,`direction, control, willpower.`,
`inner strength, bravery, compassion, focus.`,`contemplation, search for truth, inner guidance.`,`change, cycles, inevitable fate.`,
`cause and effect, clarity, truth.`,`sacrifice, release, martyrdom.`,`end of cycle, beginnings, change, metamorphosis.`,
`middle path, patience, finding meaning.`,`addiction, materialism, playfulness.`,`sudden upheaval, broken pride, disaster`,
`hope, faith, rejuvenation.`,`unconscious, illusions, intuition.`,`joy, success, celebration, positivity.`,`reflection, reckoning, awakening.`,
`fulfillment, harmony, completion.`,`new feelings, spirituality, intuition.`,`unity, partnership, connection.`,`friendship, community, happiness.`,
`apathy, contemplation, disconnectedness.`,`loss, grief, self-pity.`,`familiarity, happy memories, healing.`,
`searching for purpose, choices, daydreaming.`,`walking away, disillusionment, leaving behind.`,`satisfaction, emotional stability, luxury.`,
`inner happiness, fulfillment, dreams coming true.`,`happy surprise, dreamer, sensitivity.`,`following the heart, idealist, romantic.`,
`compassion, calm, comfort.`,`compassion, control, balance.`,`creation, willpower, inspiration, desire.`,`planning, making decisions, leaving home.`,
`looking ahead, expansion, rapid growth.`,`community, home, celebration.`,`competition, rivalry, conflict.`,`victory, success, public reward.`,
`perseverance, defensive, maintaining control.`,`rapid action, movement, quick decisions.`,`resilience, grit, last stand.`,
`accomplishment, responsibility, burden.`,`exploration, excitement, freedom.`,`action, adventure, fearlessness.`,`courage, determination, joy.`,
`big picture, leader, overcoming challenges.`,`breakthrough, clarity, sharp mind.`,`difficult choices, indecision, stalemate.`,
`heartbreak, suffering, grief.`,`rest, restoration, contemplation.`,`unbridled ambition, win at all costs, sneakiness.`,
`transition, leaving behind, moving on.`,`deception, trickery, tactics and strategy.`,`imprisonment, entrapment, self-victimization.`,
`anxiety, hopelessness, trauma.`,`failure, collapse, defeat.`,`curiosity, restlessness, mental energy.`,`action, impulsiveness, defending beliefs.`,
`complexity, perceptiveness, clear mindedness.`,`head over heart, discipline, truth.`,`opportunity, prosperity, new venture.`,
`balancing decisions, priorities, adapting to change.`,`teamwork, collaboration, building.`,`conservation, frugality, security.`,
`need, poverty, insecurity.`,`charity, generosity, sharing.`,`hard work, perseverance, diligence.`,`apprenticeship, passion, high standards.`,
`fruits of labor, rewards, luxury.`,`legacy, culmination, inheritance.`,`ambition, desire, diligence.`,`efficiency, hard work, responsibility.`,
`practicality, creature comforts, financial security.`,`abundance, prosperity, security.`]
let Reversed = [`recklessness, taken advantage of, inconsideration.`,`trickery, illusions, out of touch.`,
`lack of center, lost inner voice, repressed feelings.`,`dependence, smothering, emptiness, nosiness.`,
`tyranny, rigidity, coldness.`,`rebellion, subversiveness, new approaches.`,`loss of balance, one-sidedness, disharmony.`,
`lack of control, lack of direction, aggression.`,`self doubt, weakness, insecurity.`,`loneliness, isolation, lost your way.`,
`no control, clinging to control, bad luck.`,`dishonesty, unaccountability, unfairness.`,`stalling, needless sacrifice, fear of sacrifice.`,
`fear of change, holding on, stagnation, decay.`,`extremes, excess, lack of balance.`,`freedom, release, restoring control.`,
`disaster avoided, delayed disaster, fear of suffering.`,`faithlessness, discouragement, insecurity.`,
`confusion, fear, misinterpretation.`,`negativity, depression, sadness.`,`lack of self awareness, doubt, self loathing.`,
`incompletion, no closure.`,`emotional loss, blocked creativity, emptiness.`,`imbalance, broken communication, tension.`,
`overindulgence, gossip, isolation.`,`sudden awareness, choosing happiness, acceptance.`,`acceptance, moving on, finding peace.`,
`moving forward, leaving home, independence.`,`lack of purpose, diversion, confusion.`,`avoidance, fear of change, fear of loss.`,
`lack of inner joy, smugness, dissatisfaction.`,`shattered dreams, broken family, domestic disharmony.`,
`emotional immaturity, insecurity, disappointment.`,`moodiness, disappointment.`,`martyrdom, insecurity, dependence.`,
`coldness, moodiness, bad advice.`,`lack of energy, lack of passion, boredom.`,`fear of change, playing safe, bad planning.`,
`obstacles, delays, frustration.`,`lack of support, transience, home conflicts.`,`avoiding conflict, respecting differences.`,
`excess pride, lack of recognition, punishment.`,`give up, destroyed confidence, overwhelmed.`,
`panic, waiting, slowdown.`,`exhaustion, fatigue, questioning motivations.`,`inability to delegate, overstressed, burnt out.`,
`lack of direction, procrastination, creating conflict.`,`anger, impulsiveness, recklessness.`,`selfishness, jealousy, insecurities.`,
`impulsive, overbearing, unachievable expectations.`,`confusion, brutality, chaos.`,`lesser of two evils, no right choice, confusion.`,
`recovery, forgiveness, moving on.`,`restlessness, burnout, stress.`,`lingering resentment, desire to reconcile, forgiveness.`,
`emotional baggage, unresolved issues, resisting transition.`,`coming clean, rethinking approach, deception.`,
`self acceptance, new perspective, freedom.`,`hope, reaching out, despair.`,`can't get worse, only upwards, inevitable end.`,
`deception, manipulation, all talk.`,`no direction, disregard for consequences, unpredictability.`,`cold hearted, cruel, bitterness.`,
`manipulative, cruel, weakness.`,`lost opportunity, missed chance, bad investment.`,`loss of balance, disorganized, overwhelmed.`,
`lack of teamwork, disorganized, group conflict.`,`greediness, stinginess, possessiveness.`,`recovery, charity, improvement.`,
`strings attached, stinginess, power and domination.`,`work without results, distractions, lack of rewards.`,
`lack of passion, uninspired, no motivation.`,`reckless spending, living beyond means, false success.`,
`fleeting success, lack of stability, lack of resources.`,`lack of commitment, greediness, laziness.`,
`laziness, obsessiveness, work without reward.`,`self-centeredness, jealousy, smothering.`,`greed, indulgence, sensuality.`]
// Links - definitions & images
let cd = `https://res.cloudinary.com/demo/image/fetch/`
let tu = `https://tinyurl.com/`
let links = [`y3ud8lro`,`2e8xlooj`,`2ktgub9r`,`2o78z4zv`,`2pwzhrqt`,`2foonefr`,`ydtrruem`,`2eetxbvb`,`2jb2988l`,`y4r5xg76`,`2htyqvrb`,
`2jlbqm29`,`ybnynjdh`,`2mw3efbd`,`2luqmdak`,`2khgqh68`,`2oamnv5r`,`2k8usgmz`,`yetxotw2`,`2pbwgx6k`,`2qgndsr9`,`2n5vq2z5`,`y4cl2nud`,
`ygerpgam`,`2fvk2ymj`,`y3j7a84m`,`y6jdbede`,`y3y3cmf2`,`ydvzlkfc`,`y64dkvjs`,`y495vfdd`,`2j2gb7ov`,`yyk22opg`,`2js7599y`,`2ns8eafc`,
`2qk4jme5`,`2eberzbf`,`2eua9wlq`,`ygob755u`,`y23ad3l6`,`2lzqzj7y`,`y2d9c7uh`,`2zeu9d4m`,`2dtxhulx`,`2ommrp9d`,`2fttflcl`,`y7med93s`,
`2hm6fbkj`,`2zk2ykyg`,`2fhtbr92`,`2h8fp472`,`2zng7dlc`,`2lrcgjno`,`2hzp9zxn`,`yxgdoayq`,`2mk3al7r`,`y4kvjczz`,`2z6bbckw`,`2ghfhfwu`,
`2n9cvt5y`,`2o8w4hst`,`y47cg7ok`,`2l3c8vgj`,`2q9s28kh`,`2ntwxnpa`,`yfhks3fx`,`2ohz2zcj`,`2jvlb2su`,`2lplu6dq`,`2mlquyhp`,`2gqyfggk`,
`y5vqold2`,`y62xq5p9`,`2l6qep3f`,`2fjjv7jx`,`2j9bmrvn`,`2gxalewh`,`2kwv34tn`]
let images = [`2m8dwe7e`,`2nu68kbc`,`2znnfa7e`,`2mf5qau2`,`2eyczy3t`,`2pfktncz`,`2jvszwew`,`2er3c2kw`,`2ht9ysdd`,`2fjr6452`,`2oxkedv8`,
`2ndycjaw`,`2po6rnt8`,`2ps25czk`,`2pj22gwe`,`2nvtsxla`,`2fycshu7`,`2nbovy3h`,`2fovvbyt`,`2ldty8t9`,`2n66xw47`,`2njto6ho`,`2hyrldjc`,
`2esqvfuu`,`2qpgjpuy`,`2nqp2qog`,`2osyrsp9`,`2mdf6uk4`,`2l95duyv`,`2jljyzlb`,`2e334edr`,`2q4uhv9p`,`2f63ftoz`,`2hfzbkwt`,`2mwambuf`,
`2qmgzrcl`,`2mr5u5xl`,`2ppue466`,`2kq9we9x`,`2qulbwqs`,`2z6zj97y`,`2ojuynb2`,`2kyxa7rd`,`2lha72g5`,`2o96ceev`,`2fn8buov`,`2hvdq3pr`,
`2ef388hd`,`2k4xb6bq`,`2j4e5hkv`,`2j2nj4bx`,`2gardpc7`,`2otpe927`,`2z895mgw`,`2g7d7vpb`,`2enm69y3`,`2zr4l3ra`,`2gfw5w9y`,`2f4ctgek`,
`2lmt44ff`,`2m6jsadc`,`2pag4gfo`,`2hkn3rtn`,`2grw9qck`,`2fgdxaz6`,`2omu2lsf`,`2zc4gb6b`,`2myf33gz`,`2lx5byfp`,`2epcpmby`,`2elvjso5`,
`2hwn7mx9`,`2qr7666w`,`2n9k6po3`,`2duvc7hx`,`2ol6g8zh`,`2qwbvd3q`,`2lpt52ws`]
// Deciding reversals
let a = 1;
let b = 0; // This is for randomCards array summoning
let c = 2; // For the base64 link construction
let revlist = [`Upright`, `Reversed`];
do {
let decideRev = revlist[Math.floor(Math.random() * revlist.length)];
if (!reversals || !reversals.value || reversals.value === `no`)
{this['rev' + a] = `Upright`}
else {this['rev' + a] = decideRev}
// Reversals image link additions
if (this['rev' + a] === `Reversed`) {
this['imgRev' + a] = `a_180,`
this ['linkRev' + a] = `#rev`
} else {
this['imgRev' + a] = ``
this ['linkRev' + a] = ``
}
// Card info grabber
this['cardName' + a] = eval (`names[${randomCards[b]}]`)
this['def' + a] = eval(this['rev'+ a] + `[${randomCards[b]}]`);
this['link' + a] = tu + eval(`links[${randomCards[b]}]`) + this[`linkRev` + a];
// Base64-ing the 2nd-4th image links so it can be embedded
if (2 <= a && b < cardAmount)
{// Default card image
this['preBase' + c] = eval(`images[${randomCards[b]}]`);
this['cardImg' + c] = await base64.encode(
`${cd}${this['imgRev' + a]}w_300,f_png/${tu}${this['preBase' + c]}`);
c++;
} //end of image base64-ing
a++;
b++;
} //end of do
while (a < cardAmount + 1) // end of while
// Image link if there's only one card
let prejust1 = eval(`images[randomCards[0]]`);
let just1 = `${cd}${imgRev1}w_300,f_png/${tu}${prejust1}`;
// Myquestion handling
var myquestion
if (!question || !question.value) {myquestion = ``}
else {myquestion = `\n
•.¸¸.•´¨•.¸¸.•´¨ \`Q U E S T I O N !\`
"${question.value}"`}
// CONSTRUCTION OF MULTI CARDS SPREAD
var fullspread
var cardNames
let deckReveal = `The Original Rider-Waite Tarot`
let Shop_Link = `${tu}2n7rwbjn`
let Cover = `${tu}2lkx7veh`
// Start of ONE CARD RESULT
if (!amount || !amount.value || cardAmount === 1 || amount.value === '1')
{cardNames = `${myquestion}
**${cardName1}**
**__[${rev1}](${tu}${link1}${linkRev1})__** - ${def1}
*from **[${deckReveal}](${Shop_Link})***`;
fullspread = `${just1}`;} // end of if only one card
// Start of TWO CARDS RESULT
else {let up = `*from **[${deckReveal}](${Shop_Link})***${myquestion}\n\n`
if (cardAmount === 2 || amount.value === '2')
{cardNames = up + `\`I.\` **${cardName1}**
**__[${rev1}](${link1})__** - ${def1}
\`II.\` **${cardName2}**
**__[${rev2}](${link2})__** - ${def2}`
fullspread = cd +
`l_fetch:${cardImg2},x_305/${just1}`} // End of two cards results
// Start of THREE CARDS RESULT
else if (cardAmount === 3 || amount.value === '3')
{cardNames = up + `\`I.\` **${cardName1}**
**__[${rev1}](${link1})__** - ${def1}
\`II.\` **${cardName2}**
**__[${rev2}](${link2})__** - ${def2}
\`III.\` **${cardName3}**
**__[${rev3}](${link3})__** - ${def3}`
fullspread = cd +
`l_fetch:${cardImg2},x_305/` +
`l_fetch:${cardImg3},x_458/${just1}`} // End of three cards results
// Start of FOUR CARDS RESULT
else if (cardAmount === 4 || amount.value === '4')
{cardNames = up + `\`I.\` **${cardName1}**
**__[${rev1}](${link1})__** - ${def1}
\`II.\` **${cardName2}**
**__[${rev2}](${link2})__** - ${def2}
\`III.\` **${cardName3}**
**__[${rev3}](${link3})__** - ${def3}
\`IV.\` **${cardName4}**
**__[${rev4}](${link4})__** - ${def4}`
fullspread = cd +
`l_fetch:${cardImg2},x_305/` +
`l_fetch:${cardImg3},x_458/` +
`l_fetch:${cardImg4},x_610/${just1}`} // End of four cards results
// Start of FIVE CARDS RESULT
else
{cardNames = up + `\`I.\` **${cardName1}**
**__[${rev1}](${link1})__** - ${def1}
\`II.\` **${cardName2}**
**__[${rev2}](${link2})__** - ${def2}
\`III.\` **${cardName3}**
**__[${rev3}](${link3})__** - ${def3}
\`IV.\` **${cardName4}**
**__[${rev4}](${link4})__** - ${def4}
\`V.\` **${cardName5}**
**__[${rev5}](${link5})__** - ${def5}`
fullspread = cd +
`l_fetch:${cardImg2},x_305/` +
`l_fetch:${cardImg3},x_458/` +
`l_fetch:${cardImg4},x_610/` +
`l_fetch:${cardImg5},x_764/${just1}`} // End of five cards results
} // End of huge else
// TINYURL IMAGE LINK SHORTENING
// This is optional. If you feel like this isn't necessary, completely delete variable BUT
// in the embed, change image url to ${fullspread} instead of ${fs}
let fs = await axios
.request({
method: 'GET',
url: `http://tinyurl.com/api-create.php?url=${fullspread}`,
})
.then(function (s) {
return s.data
}) // end of tinyurl image link shortening
// SENDING EMBED TO CHANNEL
await lib.discord.interactions['@1.0.1'].followups.create({
token: context.params.event.token,
channel_id: context.params.event.channel_id,
content: ``,
embeds: [
{
type: 'rich',
title: `Your card(s)!`,
description: `${cardNames}
┈┈┈┈┈◦•✩ \`I N F O \`
**cmd** /tarot
**pulled for** ${context.params.event.member.user.username}#${context.params.event.member.user.discriminator}
**can't view spread?** [img link](${fs})`,
image: {
url: `${fs}`, // if you dont want to use tinyurl API, change to ${fullspread}
height: 0,
width: 0,
},
thumbnail: {
url: `https://res.cloudinary.com/demo/image/fetch/w_300,h_300,c_fit/${Cover}`,
height: 0,
width: 0,
},
},
],
}); // end of send message
} // end of try
// Start of error handling
catch (e) {
console.log(e)
// Start of bot sending error message to channel
await lib.discord.interactions['@1.0.1'].followups.create({
token: context.params.event.token,
channel_id: context.params.event.channel_id,
content: `**__Error__!**` // Feel free to modify your own error message
}); // end of error message sending
} // end of error handling