Message
Message
TOKEN = 'BOT_TOKEN_HERE'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='/', intents=intents)
STATS_FILE = 'rizz_stats.json'
LOGS_FILE = 'mod_logs.json'
PROBATION_DATA_FILE = 'probation_data.json'
stats = {}
mod_logs = {}
probation_data = {}
bot_messages = []
def load_stats():
global stats
if os.path.exists(STATS_FILE):
with open(STATS_FILE, 'r') as f:
stats = json.load(f)
def save_stats():
with open(STATS_FILE, 'w') as f:
json.dump(stats, f)
def load_logs():
global mod_logs
if os.path.exists(LOGS_FILE):
with open(LOGS_FILE, 'r') as f:
mod_logs = json.load(f)
def save_logs():
with open(LOGS_FILE, 'w') as f:
json.dump(mod_logs, f)
def load_probation_data():
try:
with open(PROBATION_DATA_FILE, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
def save_probation_data(data):
with open(PROBATION_DATA_FILE, 'w') as f:
json.dump(data, f, indent=4)
probation_data = load_probation_data()
def stop_bot(signal, frame):
global should_stop
should_stop = True
save_logs()
asyncio.run_coroutine_threadsafe(on_shutdown(), bot.loop)
asyncio.run_coroutine_threadsafe(bot.close(), bot.loop)
sys.exit(0)
def has_role_or_higher(*role_names):
async def predicate(interaction: discord.Interaction):
user_roles = [role.name for role in interaction.user.roles]
return any(role in user_roles for role in role_names)
return discord.app_commands.check(predicate)
@bot.event
async def on_ready():
load_stats()
load_logs()
load_probation_data()
global bot_messages
bot_messages = []
print("Bot is ready")
await
bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening,
name="Developed by whoknowslol._"))
try:
await bot.tree.sync()
commands_synced = len(bot.tree.get_commands())
print(f"Synced Commands: {commands_synced}")
except Exception as e:
print(f"An error occurred while syncing commands: {e}")
delete_bot_messages.start()
@bot.event
async def on_shutdown():
save_stats()
save_logs()
save_probation_data()
@bot.event
async def on_message(message):
if message.author == bot.user:
bot_messages.append(message)
rizz_level = stats.get(user_id, 0)
if isinstance(rizz_level, dict):
rizz_level = rizz_level.get('rizzed', 0)
yes_button.callback = yes_callback
no_button.callback = no_callback
await interaction.response.send_message(f"Are you rizzed up, {user.mention}?",
view=view)
roles_to_remove = [discord.utils.get(interaction.guild.roles,
name="Moderator"),
discord.utils.get(interaction.guild.roles, name="Trial
Moderator")]
await user.remove_roles(*roles_to_remove)
await user.add_roles(probation_role)
if probation_role in user.roles:
if str(user.id) in probation_data:
previous_roles_ids = probation_data[str(user.id)].get("previous_roles",
[])
previous_roles = [interaction.guild.get_role(role_id) for role_id in
previous_roles_ids]
probation_data.pop(str(user.id))
save_probation_data(probation_data)
await user.remove_roles(probation_role)
await user.add_roles(*previous_roles)
if user:
user_id = str(user.id)
actions = data.get(user_id, [])
if actions:
actions_text = ""
for action in actions:
moderator_id = action.get('moderator')
moderator_mention = f"<@{moderator_id}>" if moderator_id else
"Unknown"
action_str = f"**Action:** {action.get('action', 'N/A')}\n" \
f"**Moderator:** {moderator_mention}\n" \
f"**Timestamp:** {action.get('timestamp', 'N/A')}\
n" \
f"**Reason:** {action.get('reason', 'N/A')}\n\n"
actions_text += action_str
await interaction.response.send_message(embed=embed)
except Exception as e:
await interaction.response.send_message(f"An error occurred: {e}",
ephemeral=True)
@tasks.loop(minutes=1)
async def delete_bot_messages():
for message in bot_messages:
if message.author == bot.user:
try:
await message.delete()
except discord.NotFound:
pass
bot_messages.clear()
signal.signal(signal.SIGINT, stop_bot)
signal.signal(signal.SIGTERM, stop_bot)
bot.run(TOKEN)