Open-Assistant
Open-Assistant copied to clipboard
Make a discord script for searching for unverified new members
New members need to introduce themselves briefly when they join. MEE6 auto-assigns the role "unverified" to them. Once I see their short introduction (and confirm it's not spam), I assign them the "verified" role and remove "unverified". But there are so many people, sometimes I miss someone. So, if someone is good at discord, I need a way of searching through the "lobby" channel for any person who has written a message, but still has the "unverified" role.
After looking for ways to do this and finding no built in way to do it in the UI and no luck finding a discord bot that could do it I asked chatGPT to do it ~~and got a sensible enough sounding result, might be worth trying (I might see if it runs once I wake up tomorrow)~~.
EDIT: As the chatGPT suggestion is broken (see commenters below) I have hidden it to avoid confusion if someone comes across this. I was originally hoping that given we can see the required information as a user in the channel that Discord would have a way to use just the information that I as a user can see but it appears that that is not the case and a whole Discord bot is required just to programmatically access the messages in a script in the same way I can read them in the client. Given this if a bot is the route we want to take it probably makes more sense for someone familiar with making discord bots (we clearly have that skill set floating around) and make a proper bot that can copy unverified users posts in the lobby into a DM and then the user DM'd could use reactions to that message to automate setting the correct roles for the user.
Broken chatGPT suggestion
>Write a python script that uses the discord API to find messages in a channel from users with the role "unverified".chatGPT
To use the Discord API, you will need to install the discord.py library. You can do this by running the following command:
pip install discord.py
Next, you will need to create a Discord bot and get its token. You can follow the instructions here to do this.
Once you have the discord.py library installed and have a bot set up, you can use the following script to find messages from users with the "unverified" role in a specific channel.
import discord
# Replace YOUR_BOT_TOKEN with your bot's token
client = discord.Client(token='YOUR_BOT_TOKEN')
# Replace CHANNEL_ID with the ID of the channel you want to search
channel_id = CHANNEL_ID
# Replace UNVERIFIED_ROLE_ID with the ID of the "unverified" role
unverified_role_id = UNVERIFIED_ROLE_ID
@client.event
async def on_ready():
# Find the channel object
channel = client.get_channel(channel_id)
# Get a list of all messages in the channel
messages = await channel.fetch_messages()
# Iterate through the messages and print the ones from users with the "unverified" role
for message in messages:
if unverified_role_id in [role.id for role in message.author.roles]:
print(message.content)
client.run()
This script will print the content of all messages in the specified channel that were sent by users with the "unverified" role.
@othrayte unfortunately it doesn't work as it is. However, I've built a script that works using your code:
import discord
unverified_users = set()
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
# Find the channel object
channel = client.get_channel(CHANNEL_ID)
# Get a list of all messages in the channel
messages = channel.history(limit=200)
# Iterate through the messages and print the ones from users with the "unverified" role
async for message in messages:
if isinstance(message.author, discord.Member) and UNVERIFIED_ROLE_ID in [
role.id for role in message.author.roles
]:
unverified_users.add(message.author.name)
print(f"All unverified users: {unverified_users}")
await client.close()
client.run(BOT_TOKEN)
import discord
client = discord.Client()
@client.event
async def on_ready():
lobby_channel = discord.utils.get(client.get_all_channels(), name="lobby")
unverified_role = discord.utils.get(client.guild.roles, name="unverified")
unverified_members = [member for member in client.guild.members if unverified_role in member.roles]
for member in unverified_members:
async for message in lobby_channel.history(limit=None):
if message.author == member:
print(f"{member.name} has sent a message in the lobby channel and has the unverified role.")
client.run("YOUR_DISCORD_BOT_TOKEN")
Thank you very much everyone, I took both suggestions and a bit of copilot made scripts/discord/verify-lobby.py