Automatically Assign a Discord Role to Every New Twitch Follower
When someone follows your Twitch channel, this workflow instantly assigns them a designated role in your Discord server. Keep your community organized and reward followers without any manual work.
- 1
Schedule a Twitch follower check every 5 minutes
Add a
Schedule Triggernode and set the interval to every 5 minutes. This is the heartbeat of the workflow, regularly checking for new followers on your channel. No credentials are needed here. - 2
Fetch your latest Twitch followers
Add an
HTTP Requestnode. Set theMethodto GET and theURLtohttps://api.twitch.tv/helix/channels/followers?broadcaster_id=YOUR_BROADCASTER_ID&first=5. In theHeaderssection addClient-Idwith your Twitch app client ID andAuthorizationwithBearer YOUR_ACCESS_TOKEN. Store these securely in n8n credentials. This returns the most recent followers. - 3
Extract the latest follower's username
Add a
Setnode to pull out the follower data you need. Create a new field calledfollowerNameand set its value to the expression{{ $json.data[0].user_name }}. This isolates the most recent follower's username for the next step. - 4
Look up the Discord member by username
Add another
HTTP Requestnode. SetMethodto GET andURLtohttps://discord.com/api/v10/guilds/YOUR_GUILD_ID/members/search?query={{ $json.followerName }}&limit=1. Add aAuthorizationheader with valueBot YOUR_BOT_TOKEN. This searches your Discord server for a member whose username matches the Twitch follower. Store the bot token in n8n credentials. - 5
Assign the Discord role to the matched member
Add a final
HTTP Requestnode. SetMethodto PUT andURLtohttps://discord.com/api/v10/guilds/YOUR_GUILD_ID/members/{{ $json[0].user.id }}/roles/YOUR_ROLE_ID. Add theAuthorizationheader withBot YOUR_BOT_TOKENand setBody Content Typeto JSON with an empty body{}. This grants the Twitch Follower role to the matched Discord member instantly.
Frequently asked questions
What if the Twitch follower doesn't have the same name on Discord?
The workflow matches by username, so if usernames differ the role won't be assigned automatically. You can add a manual mapping sheet or ask followers to link their accounts via a bot command as an additional step outside this workflow.
How do I get a Twitch broadcaster ID?
Go to https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/ and enter your Twitch username. Alternatively call the Twitch API endpoint GET /helix/users?login=YOUR_USERNAME with your credentials and copy the `id` field from the response.
What Discord bot permissions does the bot need?
Your Discord bot must have the `Manage Roles` permission enabled in your server. Also ensure the bot's role is positioned higher in the role hierarchy than the role it is trying to assign, otherwise Discord's API will return a 403 error.