Skip to content

Instantly share code, notes, and snippets.

@OlMi1
Created July 3, 2023 11:24
Show Gist options
  • Save OlMi1/b432a454f1174f1b0448e1a50bfdd8b9 to your computer and use it in GitHub Desktop.
Save OlMi1/b432a454f1174f1b0448e1a50bfdd8b9 to your computer and use it in GitHub Desktop.
BUBot
# Gives people roles based on dates. Can be used for any purpose. Translate if you want.
import discord, re
from discord.ext import commands
from random import randint
registerTestDateChannelID = CHANNELID
intents = discord.Intents.default()
intents.reactions = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
# When a message in reactionChannelID is sent by a user
@bot.event
async def on_message(message):
if message.channel.id == registerTestDateChannelID and message.author != bot.user:
# get message content
content = message.content
print("Content: " + content)
# Check if the message content matches the format dd.mm
if re.match(r"^\d{2}\.\d{2}\.", content):
# Give the user the role with that name (if it exists), else create it. Role date format: "BU dd.mm"
roleName = "BU " + content
role = discord.utils.get(message.guild.roles, name=roleName)
if role is None:
role = await message.guild.create_role(name=roleName, mentionable=True, color=discord.Color.from_rgb(randint(0, 255), randint(0, 255), randint(0, 255)))
await message.author.add_roles(role)
await message.channel.send(f'{message.author.mention} Du hast die Rolle für die BU am {content} erhalten.')
else:
await message.channel.send(f'{message.author.mention} Gib das Datum bitte im Format dd.mm. an (z.B. 29.08.)')
bot.run("TOKEN")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment