Reddit Discord and Meta API

Reddit & Discord integration

Meta API
6 min readAug 3, 2022

If you’re a subreddit owner and a Discord server owner, you may want to keep your Discord channel in sync with your subreddit.

Sometimes, it can get difficult to do the syncing manually. You may also want to post different threads from different subreddits automatically to your Discord channel to make your server more attractive. You can try finding different tools online but you won’t find any tool to automate this process. But we’re gonna help you to automate this process.

This tutorial will help you to create a Discord bot that’ll fetch the latest posts from different subreddits and message those posts with their link in a Discord channel.

Prerequisites

* Meta API Account

* Discord Account

Step -1: Create a Discord bot and get the API credentials

The very first step here is to create a Discord bot. So, log in to the Discord web version and go to this [ URL]. You should see the below page:

Now click on New Application, and give it a sweet name.

Once you have created the application, you should see the below page:

It means that we have successfully created the application. Now, we need to create a Discord bot using this application. In the left menubar you’ll see the “Bot” section, click on it. You should see the below page:

After creating the bot, you now need to give it the required permissions in order to send messages to your owned channels. If you scroll to the bottom of the same page, you should be able to see a section called “Bot Permissions”. Tick the Administrator checkbox.

Now find the button that says “Reset Token” in order to generate a new API token. After clicking on it, make sure to store the newly generated token in a safe place (we’ll need that token further in this tutorial).

Finally, we’re done with the boring part. Let’s move ahead with the more interesting part!

Step -2: Adding the bot to your Discord server

On the same page, if you look in the left menu bar, you should see a section called ‘OAuth2’. If you click on OAuth -> URL Generator. You should see the below page:

Check the checkbox that says “Bot” and you should see another form like this:

In the second form, check the checkbox that says, Administrator. At the booth of the page, there’s a section called Generated URL. Now copy that URL and open it in a new tab.

You now need to select your Discord channel and then Authorize it.

That’s it! You have finally added your Discord bot to your server!

Step -3: Create a spell using Meta API

Now login to your Meta API account and click on Create a Spell button.

For now, let’s move ahead with Empty Spell.

Give it a sweet name and continue.

After creating the spell, you should see the below page:

Step -4: Add a Discord connector

* A connector in Meta-API allows you to connect to more than 500 APIs without writing down a single line of code. You can perform a lot of actions using these connectors. Meta-API also allows you to use multiple connectors in a single Spell allowing you to make complex actions in a Spell. *

If you look at the left side of the Spell page, you should see a “+” button i.e. for adding new connectors. You should see the below window:

Now, search for Discord and click on the Create Message box from the list of options.

In the end, click on Add Discord Connector.

Step -5: Fetching Reddit posts and sending them to the Discord channel

In the code editor, replace the existing code with the below code:

*Note: Make sure to replace the placeholder “YOUR_CONNECTOR_ID HERE” with your unique connector id.*

Code Explanation

In the above code, we’re making a GET request to Reddit’s API and fetching the top 10 latest posts. You can replace `/r/Python` with any subreddit you want to. After that, we’re formatting the message for our Discord channel so that it contains the heading that says `Top 10 POSTS in r/Python`.

Once you’re done, you now need to add the API key and the channel ID in the connector. If you look at the right half of the Spell page, you’ll see the below form:

In the Authentication section, you need to click on the “+” button to add Discord’s API key and in the params section, you need to put the channel id where you want to send the message in your Discord server.

After everything’s done, click on the “Run” button to test the Spell. If everything’s working fine, you should see a new message on your Discord channel like this one:

Reedit feed in Discord Channel

Troubleshooting

* If you see the below error in the console:

You’re missing the Axios dependency. At the footer of the page, you’ll see a menu called “Dependencies”. Click on it, search for Axios and click on the Save Dependency button. It should resolve the missing dependency issue.

* If you get the error “Discord is not in your spell code”, you’ll need to crosscheck this line in the code `connectorService.config(“YOUR_CONNECTOR_ID_HERE”, {body: {“content”: formatted_message} as Bodypostchannelschannelidmessages})` and replace the placeholder “YOUR_CONNECTOR_ID_HERE” with your generated connector ID.

* If you’re not receiving any message from the Bot, you can try adding it again to the server or you can also try generating a new API key and use that one to send the messages.

Final Words

Meta-API allows you to connect multiple connectors in a Spell. Let’s say if you want to send the same message to a Slack channel, you just need to add another connector for Slack and you’re good to go. We have a lot of [ready-to-use Spells] also that you can directly use without any hassle. You can even make changes to the existing ready-to-use Spells as per your requirements and add multiple connectors.

Originally published at https://blog.meta-api.io.

--

--

Meta API
Meta API

Written by Meta API

Meta API is where integration becomes an extension of your team, enabling you to consistently deliver innovation with speed and agility.

No responses yet