Last active
April 3, 2021 01:50
-
-
Save nfitzen/890bbf6919f685fefdf642bf04e1125d to your computer and use it in GitHub Desktop.
Autorole with membership screening
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# SPDX-FileCopyrightText: 2021 Nathaniel Fitzenrider <https://github.com/nfitzen> | |
# | |
# SPDX-License-Identifier: CC0-1.0 | |
# Note: only works with membership screening enabled. | |
import discord | |
ROLE_ID = None | |
bot = discord.Client() | |
@bot.event | |
async def on_member_update(before, after): | |
global ROLE_ID | |
guild = after.guild | |
try: | |
if ROLE_ID: | |
if before.pending and not after.pending: | |
role = guild.get_role(ROLE_ID) | |
after.add_roles(role) | |
except discord.Forbidden as e: | |
print(e) | |
if __name__ == "__main__": | |
print("Note: only works with membership screening enabled.") | |
try: | |
with open('token.txt') as f: | |
token = f.read() | |
except IOError: | |
print("Couldn't read the token.") | |
token = input("Discord token: ") | |
try: | |
with open('roleid.txt') as f: | |
ROLE_ID = f.read() | |
except IOError: | |
print("Couldn't read the role ID.") | |
ROLE_ID = input("Role ID: ") | |
bot.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment