#reddit command
212 messages · Page 1 of 1 (latest)
i would also like to use gifs too
snoowrap is/was a relatively popular npm package that's a reddit API wrapper
so i can use this
?
I use it in one of my bots, so it's up to you
You can also just make raw fetch() requests to Reddit
you dont need to use snoowrap for this, their api is pretty easy to use
https://www.reddit.com/r/gifs/new.json
https://www.reddit.com/r/gifs/top.json
etc
https://www.reddit.com/dev/api#GET_hot
how do i do that
but i want gifs from other subreddits
literally just replace gifs in the url with whatever subreddit you want
Documentation suggestion for @molten granite:
Fetch API
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set.
?
that'll give you the top 50 posts for /r/gifs, yeah
and itll show gifs?
it works
tysm
one more question
how do i make the image look bigger if i cna
can
i also cant seem to not make it random,
since mine is /random/.json
change it to /random.json
but do i have to use random
i wanna use hot
or just something else
fetch the hot posts then get a random one from the posts it gives
not rlly another way
okay
ill try to do this
even though i might need help
this is so confusing
imma keep it as is tbh but all i wanna do is just make it so that you can choose from different reddit communities
how would i make it show up if it was a video?
and show what subreddit it is (im sorry if im annoying you)
also thank you for the help
i really appreciate it
now i just gotta figure out how to do it so that i can choose a subreddit
agh
idk what i can do
choosing a subreddit is just changing the URL you're fetching
but how can i make it so you choose where it fetches from
that's up to you
a String option in your slash command is probably the most efficient
oh ok
i dont really know what u mean but
i need an example
what do you not understand
are you using slash commands?
yes
i am
Slash Commands: Command options
read more
so i looked at choices one
would it be like that?
If you want to limit what they can choose, yes
hmm
ok so for example
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('gif')
.setDescription('Sends a random gif!')
.addStringOption(option =>
option.setName('category')
.setDescription('The gif category')
.setRequired(true)
.addChoices(
{ name: 'Funny', value: `https://www.reddit.com/r/memes/random.json` },
{ name: 'Meme', value: 'gif_meme' },
{ name: 'Movie', value: 'gif_movie' },
)),
async execute(interaction) {
const category = interaction.options.getString('category');
// category must be one of 'gif_funny', 'gif_meme', or 'gif_movie'
},
};``` would it look something like this for example
or would it be something else
god damn it
im so lost
That's a good start
phew
You can make each of the values a url, and just fetch the url when you receive it
ok
so when i do the url i can do like await fetch(funny)
?
If funny is the name of your option variable, then yes
ok
do i keep the const category?
i wanna make it an embed
that's how the guide defined the name of the option variable
so like /reddit rfunny and it would send an embed of that subreddit
A reddit URL will automatically embed into Discord
ah
so then how do i do the options part
Look at the code from the guide, and try to understand what it means
specifically, look in the body of execute()
okay
same place u told me about?
Yes, and the same place where you pasted the code above
okay
okay so what happens is that the command options show up but when i press funny it doesnt respond
im so close i can smell it bro
do you have code that responds to the command?
no
what would that be tho
interaction.reply(...)
okay
when i try the command it says that 'name' is undefined
const { SlashCommandBuilder } = require('discord.js');
const { EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('reddit')
.setDescription('Sends a random pic/gif from reddit!')
.addStringOption(option =>
option.setName('category')
.setDescription('The reddit category')
.setRequired(true)
.addChoices(
{ name: 'r/funny', value: `https://www.reddit.com/r/memes/random/.json` },
{ name: 'Meme', value: 'gif_meme' },
{ name: 'Movie', value: 'gif_movie' },
)),
async execute(interaction) {
const category = interaction.options.getString('category');
const reddit = await r.json()
let title = reddit[0].data.children[0].data.title;
let image = reddit[0].data.children[0].data.url;
let author = reddit[0].data.children[0].data.author;
const embed = new EmbedBuilder()
.setColor("Blue")
.setTitle(`${title}`)
.setImage(`${image}`)
.setURL(`${image}`)
.setAuthor( {text: author} )
// category must be one of 'gif_funny', 'gif_meme', or 'gif_movie'
await interaction.reply({ embeds: [embed] })
},
};``` heres the code
Documentation suggestion for @molten granite:
EmbedBuilder#setAuthor()
Sets the author of this embed
Look at the parameters of this function
would it be name ==
That's not how objects work
Also, I already see a reference error since you never defined r
oh
yea i never defined that
idk how i can though given that i cant do async r => {}
well what do you expect r to be?
the stuff for reddit
what stuff for reddit? do you want it to pick a random subreddit that exists?
um
this was the code im trying to use
do you notice anything missing between their code and your code?
async function meme() {}
and the fetch and async r
so, how are they defining r?
um
putting the embed and other stuff in the .then(async r => {}
Not quite
oh
The . means that then() is a property (a method, specifically) of what comes before it
Therefore, what comes before .then() is essential for it to work
Now I ask you, what comes before .then()?
the fetch
and the async function
Does your current code include the fetch?
no
Do you think you need to fetch the reddit url so your code knows which subreddit to get?
yes
You should probably add that too, then
but how would i do that if its only going to be a specific link
Do you have any variable that contains a link to the reddit URL that the user chose?
value: reddit link
would that be one or?
do i need to make a variable like rfunny = reddit link and put
value: rfunny
That's a choice you're giving the user, but what variable do you have that represents the user's specific choice?
none
thats why i said
rfunny = reddit link
and i would put
value: rfunny
What does category represent in your code?
The variable, not the stuff in your slash command builder
the option.setName
const category = interaction.options.getString('category');
If you did console.log(category), what do you think it would log?
umm
undefined?
Why would it be undefined?
because its not anywhere in the execute function
i have the const but didnt put it anywhere else
It's literally defined in the first line in the body of your execute function
So, why do you think this variable exists?
i have to put it into the interaction.reply?
What would it reply with? If you just did interaction.reply(category), what do you think it would send?
an error
so its gonna be embed and category
There's nothing erroneous about that line of code
You could actually try to log or send the variable, and it would probably help you understand what you need it for
console.log(category)
failed to parse URL from undefined
so the name is still undefined
Comment out all the other code
Just define and log category for now
ok
how much of the code
The body of the execute() function
this what it is
this should be commented out, too
got it
it sent the link in the terminal
So, what does that tell you that category represents?
the reddit link
So, what do you think you should be fetching?
the reddit linl
link
What code would that look like?
so await fetch(category)
Perfect
yess
what would i do with the other code?
Uncomment it out, and look back at the copied code to see the differences between the two
ok
do i need r.json still?
Yes, it is essential
got it
yes
i think i got it
nope it gave an error
what error?
setFooter()'s argument has a property called text
setAuthor()'s argument has a property called name
Right now, you're using setAuthor() with text which is incorrect
ah
wait so what do i do
Pick the method you want to use, and use the correct argument for that method
um
so what do i need to fix
i dont understand
do i change it to name?
it works!

W
tysm
will i have to manually put the subreddits in?
and can i do mp4's?
You can add them as more choices, up to 25 choices max
😮
i didnt know that
You can't send videos in an embed's image
how can i fix the 25 choice max?
like extend it
Just include more { name, value } objects in your addChoices()
oh is it only 25 choices shown?
If you try to include more, it will throw an error
so what do i do to prevent that error
or can i not
Use autocomplete
Slash Commands: Responding to autocomplete interactions
read more
uhh
Slash Commands: Autocomplete
read more
Use that to dynamically respond with up to 25 choices based on what the user entered yet…