Custom Linked Roles in Discord

I’ve seen in the Discord Developers Docs that I could make an Custom Linked role, But it has TypeScript Example which I don’t know how to use TypeScript, Does anybody know how to make Custom Linked Role using nextcord?

Yes, you can create a custom linked role using the nextcord library in Python. A custom linked role is a role that is tied to a user’s external account, such as a Twitch or GitHub account. When a user links their account to your Discord server, you can assign them a custom role that gives them special permissions or access to exclusive channels.

To create a custom linked role using nextcord, you will need to use the on_member_update event. This event is triggered whenever a member’s status, roles, or nickname are updated. You can use this event to check if the member has linked their external account and assign them a custom role.

Here’s an example code snippet that demonstrates how to create a custom linked role using nextcord:

import nextcord

client = nextcord.Client()

@client.event
async def on_member_update(before, after):
    linked_role = nextcord.utils.get(after.guild.roles, name='Linked Role')

    if linked_role not in before.roles and linked_role in after.roles:
        # User linked their account
        # Assign them a custom role here
        custom_role = nextcord.utils.get(after.guild.roles, name='Custom Role')
        await after.add_roles(custom_role)

client.run('your-bot-token-here')

In this example, we define the on_member_update event handler and check if the user has the Linked Role role. If the user has this role, we can assume that they have linked their external account, and we can assign them the Custom Role role using the add_roles method.

Note that you will need to replace 'your-bot-token-here' with your actual bot token. You will also need to replace 'Linked Role' and 'Custom Role' with the names of the roles you want to use.

2 Likes