This commit is contained in:
TheErrorExe 2024-12-21 22:31:52 +01:00 committed by GitHub
parent 777d1c8f5d
commit ca80c52260
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

68
bot.py
View File

@ -11,6 +11,28 @@ bot = commands.Bot(command_prefix='!', intents=intents, description="Developed b
@bot.event @bot.event
async def on_ready(): async def on_ready():
print(f'Bot is ready. Logged in as {bot.user}') print(f'Bot is ready. Logged in as {bot.user}')
# Synchronisieren der Slash Commands
await bot.tree.sync()
# Automatically leave if the bot joins a server with an ID other than 1302694379299016764
@bot.event
async def on_guild_join(guild):
if guild.id != 1302694379299016764:
# Try to send a message to a default text channel
for channel in guild.text_channels:
if channel.permissions_for(guild.me).send_messages:
try:
await channel.send(
"This bot can only be in 'ReviveMii Trusted Servers'. "
"Please ensure you're in a trusted server. Leaving this server now..."
)
print(f"Sent leave message to {guild.name} before leaving.")
break # Once the message is sent, break the loop
except discord.Forbidden:
print(f"Bot doesn't have permission to send messages in {channel.name} of {guild.name}")
await guild.leave()
print(f"Left the server: {guild.name} (ID: {guild.id})")
async def fetch_errors(): async def fetch_errors():
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
@ -41,35 +63,40 @@ def search_errors(errors, query):
results.append(f'{code}: {description}') results.append(f'{code}: {description}')
return results return results
@bot.command(help="!error : Wii Error Codes. How to use: !error InsertErrorCodeHere") # Slash Command für Fehlercodes
async def error(ctx, *, query: str): @bot.tree.command(name="error", description="Fetch Wii Error Codes")
async def error(interaction: discord.Interaction, query: str):
errors = await fetch_errors() errors = await fetch_errors()
results = search_errors(errors, query) results = search_errors(errors, query)
if results: if results:
await ctx.send('\n'.join(results)) await interaction.response.send_message('\n'.join(results))
else: else:
await ctx.send('No Error Codes found.') await interaction.response.send_message('No Error Codes found.')
@bot.command(help="!about : Shows Information about the bot.") # Slash Command für Bot-Informationen
async def about(ctx): @bot.tree.command(name="about", description="Shows Information about the bot.")
await ctx.send('This bot was developed by TheErrorExe. Source Code: https://github.com/ReviveMii/discordbot') async def about(interaction: discord.Interaction):
await interaction.response.send_message('This bot was developed by TheErrorExe. Source Code: https://github.com/ReviveMii/discordbot')
@bot.command(help="!website : Shows the Website of the Developer.") # Slash Command für die Website des Entwicklers
async def website(ctx): @bot.tree.command(name="website", description="Shows the Website of the Developer.")
await ctx.send('ReviveMii: https://revivemii.fr.to\nTheErrorExe-Homepage: https://theerrorexe.github.io\nTools: https://theerrorexe-tools.github.io') async def website(interaction: discord.Interaction):
await interaction.response.send_message('ReviveMii: https://revivemii.fr.to\nTheErrorExe-Homepage: https://theerrorexe.github.io\nTools: https://theerrorexe-tools.github.io')
@bot.command(help="!ping : Ping Pong!") # Slash Command für Ping
async def ping(ctx): @bot.tree.command(name="ping", description="Ping Pong!")
await ctx.send('Pong!') async def ping(interaction: discord.Interaction):
await interaction.response.send_message('Pong!')
@bot.command(help="!status : Check the operational status of the website.") # Slash Command für den Status der Website
async def status(ctx): @bot.tree.command(name="status", description="Check the operational status of the website.")
async def status(interaction: discord.Interaction):
# Initial status message # Initial status message
status_msg = await ctx.send( status_msg = await interaction.response.send_message(
"Website : Checking...\n" "Website : Checking...\n"
"More Information at https://revivemii.fr.to/status/" "More Information at https://revivemii.fr.to/status/"
) )
async def check_website(url): async def check_website(url):
try: try:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
@ -80,9 +107,9 @@ async def status(ctx):
return "Server Down" return "Server Down"
except Exception: except Exception:
return "Server Down" return "Server Down"
https_status = await check_website("https://revivemii.fr.to") https_status = await check_website("https://revivemii.fr.to")
# Update the status message with the results # Update the status message with the results
await status_msg.edit( await status_msg.edit(
content=( content=(
@ -91,8 +118,9 @@ async def status(ctx):
) )
) )
# Read the token from token.txt # Bot-Token lesen
with open('token.txt', 'r') as file: with open('token.txt', 'r') as file:
token = file.read().strip() token = file.read().strip()
# Bot ausführen
bot.run(token) bot.run(token)