Skip to content

Commit 3479223

Browse files
committed
Update bot to version 1.7.7 and improve command handling
- Bumped bot version to 1.7.7 in Dockerfile and `main.py`. - Refactored commands to use `followup.send` for deferred responses. - Added `@guild_only` decorator to restrict `permissions_command` to guilds. - Enhanced `permissions_command` logic for better permission checks. - Rewrote `botinfo_command` for improved readability and consistency. - Updated `discord.py` dependency to >2.0.0 in `requirements.txt`. - Improved code readability, maintainability, and user feedback.
1 parent bee7b1a commit 3479223

File tree

3 files changed

+63
-60
lines changed

3 files changed

+63
-60
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ LABEL maintainer="Discord: pika.pika.no.mi (970119359840284743)" \
2929
description="This bot automatically publishes messages in announcement channels on discord." \
3030
release=$BUILD_DATE \
3131
url="https://github.com/Serpensin/DiscordBots-AutoPublisher" \
32-
version="1.7.6"
32+
version="1.7.7"
3333

3434
CMD ["python3", "main.py"]

main.py

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#Init
2525
discord.VoiceClient.warn_nacl = False
2626
load_dotenv()
27-
BOT_VERSION = '1.7.6'
27+
BOT_VERSION = '1.7.7'
2828
APP_FOLDER_NAME = 'AutoPublisher'
2929
BOT_NAME = 'AutoPublisher'
3030
if not os.path.exists(f'{APP_FOLDER_NAME}//Logs'):
@@ -599,104 +599,107 @@ async def broadcast(message):
599599
@tree.command(name = 'support', description = 'Get invite to our support server.')
600600
@discord.app_commands.checks.cooldown(1, 60, key=lambda i: (i.user.id))
601601
async def support_invite_command(interaction: discord.Interaction):
602+
await interaction.response.defer(ephemeral = True)
603+
602604
if str(interaction.guild.id) != SUPPORT_ID:
603-
await interaction.response.defer(ephemeral = True)
604605
await interaction.followup.send(await Functions.create_support_invite(interaction), ephemeral = True)
605606
else:
606-
await interaction.response.send_message('You are already in our support server!', ephemeral = True)
607+
await interaction.followup.send('You are already in our support server!', ephemeral = True)
607608

608609

609610
#Tell user what permissions are required
610611
@tree.command(
611612
name='permissions',
612613
description='Tell what permissions are required or check if the bot has necessary permissions in a channel.'
613614
)
615+
@discord.app_commands.guild_only()
614616
@discord.app_commands.describe(choice='Choose an option.', channel='Select channel.')
615617
@discord.app_commands.choices(choice=[
616618
discord.app_commands.Choice(name="Explain permissions", value="explain"),
617619
discord.app_commands.Choice(name="Check bot permissions", value="check")
618620
])
619621
async def permissions_command(interaction: discord.Interaction, choice: str, channel: discord.abc.GuildChannel = None):
620-
if interaction.guild is None:
621-
await interaction.response.send_message('This command can only be used in a server.', ephemeral=True)
622-
return
622+
await interaction.response.defer(ephemeral=True)
623+
623624
if interaction.user.guild_permissions.manage_roles or interaction.user.guild_permissions.manage_channels:
624625
if choice == 'explain':
625-
await interaction.response.send_message('In order for this bot to be able to publish messages, he needs the following permissions for each channel he publishes messages for:\n`View Channel`, `Send Messages`, `Manage Messages` and `Read Message History`.', ephemeral=True)
626+
await interaction.followup.send('In order for this bot to be able to publish messages, he needs the following permissions for each channel he publishes messages for:\n`View Channel`, `Send Messages`, `Manage Messages` and `Read Message History`.', ephemeral=True)
626627
elif choice == 'check':
627628
if channel is None:
628-
await interaction.response.send_message('Please specify a channel.', ephemeral=True)
629+
await interaction.followup.send('Please specify a channel.', ephemeral=True)
629630
return
630631

631632
if isinstance(channel, discord.TextChannel):
632633
if not channel.is_news():
633-
await interaction.response.send_message('The specified channel is not an announcement channel.', ephemeral=True)
634+
await interaction.followup.send('The specified channel is not an announcement channel.', ephemeral=True)
634635
return
635636

636637
perms = channel.permissions_for(interaction.guild.me)
637638
needed_permissions = ['view_channel', 'send_messages', 'manage_messages', 'read_message_history', 'add_reactions']
638639
missing_permissions = [perm for perm in needed_permissions if not getattr(perms, perm)]
639640

640641
if interaction.guild.me.guild_permissions.administrator:
641-
await interaction.response.send_message('The bot has Administrator, so he has all the necessary permissions in this channel.', ephemeral=True)
642+
await interaction.followup.send('The bot has Administrator, so he has all the necessary permissions in this channel.', ephemeral=True)
642643
elif not missing_permissions:
643-
await interaction.response.send_message('The bot has all the necessary permissions in this channel.', ephemeral=True)
644+
await interaction.followup.send('The bot has all the necessary permissions in this channel.', ephemeral=True)
644645
else:
645-
await interaction.response.send_message(f'The bot is missing the following permissions in this channel: {", ".join(missing_permissions)}.\nYou can also give him Administrator.', ephemeral=True)
646+
await interaction.followup.send(f'The bot is missing the following permissions in this channel: {", ".join(missing_permissions)}.\nYou can also give him Administrator.', ephemeral=True)
646647
else:
647-
await interaction.response.send_message('Please specify a text channel.', ephemeral=True)
648+
await interaction.followup.send('Please specify a text channel.', ephemeral=True)
648649
else:
649-
await interaction.response.send_message('You need the `manage_roles` or `manage_channels` permission to use this command.', ephemeral=True)
650+
await interaction.followup.send('You need the `manage_roles` or `manage_channels` permission to use this command.', ephemeral=True)
650651

651652

652653
#Bot Information
653654
@tree.command(name = 'botinfo', description = 'Get information about the bot.')
654655
@discord.app_commands.checks.cooldown(1, 60, key=lambda i: (i.user.id))
655656
async def botinfo_command(interaction: discord.Interaction):
656-
member_count = sum(guild.member_count for guild in bot.guilds)
657-
658-
embed = discord.Embed(
659-
title=f"Information about {bot.user.name}",
660-
color=discord.Color.blue()
661-
)
662-
embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else '')
663-
664-
embed.add_field(name="Created at", value=bot.user.created_at.strftime("%d.%m.%Y, %H:%M:%S"), inline=True)
665-
embed.add_field(name="Version", value=BOT_VERSION, inline=True)
666-
embed.add_field(name="Uptime", value=str(datetime.timedelta(seconds=int((datetime.datetime.now() - start_time).total_seconds()))), inline=True)
667-
668-
embed.add_field(name="Owner", value=f"<@!{OWNERID}>", inline=True)
669-
embed.add_field(name="\u200b", value="\u200b", inline=True)
670-
embed.add_field(name="\u200b", value="\u200b", inline=True)
671-
672-
embed.add_field(name="Server", value=f"{len(bot.guilds)}", inline=True)
673-
embed.add_field(name="Member count", value=str(member_count), inline=True)
674-
embed.add_field(name="\u200b", value="\u200b", inline=True)
675-
676-
embed.add_field(name="Shards", value=f"{bot.shard_count}", inline=True)
677-
embed.add_field(name="Shard ID", value=f"{interaction.guild.shard_id if interaction.guild else 'N/A'}", inline=True)
678-
embed.add_field(name="\u200b", value="\u200b", inline=True)
679-
680-
embed.add_field(name="Python", value=f"{platform.python_version()}", inline=True)
681-
embed.add_field(name="discord.py", value=f"{discord.__version__}", inline=True)
682-
embed.add_field(name="Sentry", value=f"{sentry_sdk.consts.VERSION}", inline=True)
683-
684-
embed.add_field(name="Repo", value=f"[GitHub](https://github.com/Serpensin/DiscordBots-AutoPublisher)", inline=True)
685-
embed.add_field(name="Invite", value=f"[Invite me](https://discord.com/oauth2/authorize?client_id={bot.user.id})", inline=True)
686-
embed.add_field(name="\u200b", value="\u200b", inline=True)
687-
688-
if interaction.user.id == int(OWNERID):
689-
# Add CPU and RAM usage
690-
process = psutil.Process(os.getpid())
691-
cpu_usage = process.cpu_percent()
692-
ram_usage = round(process.memory_percent(), 2)
693-
ram_real = round(process.memory_info().rss / (1024 ** 2), 2)
694-
695-
embed.add_field(name="CPU", value=f"{cpu_usage}%", inline=True)
696-
embed.add_field(name="RAM", value=f"{ram_usage}%", inline=True)
697-
embed.add_field(name="RAM", value=f"{ram_real} MB", inline=True)
698-
699-
await interaction.response.send_message(embed=embed)
657+
await interaction.response.defer(ephemeral = False)
658+
659+
member_count = sum(guild.member_count for guild in bot.guilds)
660+
661+
embed = discord.Embed(
662+
title=f"Information about {bot.user.name}",
663+
color=discord.Color.blue()
664+
)
665+
embed.set_thumbnail(url=bot.user.avatar.url if bot.user.avatar else '')
666+
667+
embed.add_field(name="Created at", value=bot.user.created_at.strftime("%d.%m.%Y, %H:%M:%S"), inline=True)
668+
embed.add_field(name="Version", value=BOT_VERSION, inline=True)
669+
embed.add_field(name="Uptime", value=str(datetime.timedelta(seconds=int((datetime.datetime.now() - start_time).total_seconds()))), inline=True)
670+
671+
embed.add_field(name="Owner", value=f"<@!{OWNERID}>", inline=True)
672+
embed.add_field(name="\u200b", value="\u200b", inline=True)
673+
embed.add_field(name="\u200b", value="\u200b", inline=True)
674+
675+
embed.add_field(name="Server", value=f"{len(bot.guilds)}", inline=True)
676+
embed.add_field(name="Member count", value=str(member_count), inline=True)
677+
embed.add_field(name="\u200b", value="\u200b", inline=True)
678+
679+
embed.add_field(name="Shards", value=f"{bot.shard_count}", inline=True)
680+
embed.add_field(name="Shard ID", value=f"{interaction.guild.shard_id if interaction.guild else 'N/A'}", inline=True)
681+
embed.add_field(name="\u200b", value="\u200b", inline=True)
682+
683+
embed.add_field(name="Python", value=f"{platform.python_version()}", inline=True)
684+
embed.add_field(name="discord.py", value=f"{discord.__version__}", inline=True)
685+
embed.add_field(name="Sentry", value=f"{sentry_sdk.consts.VERSION}", inline=True)
686+
687+
embed.add_field(name="Repo", value=f"[GitHub](https://github.com/Serpensin/DiscordBots-AutoPublisher)", inline=True)
688+
embed.add_field(name="Invite", value=f"[Invite me](https://discord.com/oauth2/authorize?client_id={bot.user.id})", inline=True)
689+
embed.add_field(name="\u200b", value="\u200b", inline=True)
690+
691+
if interaction.user.id == int(OWNERID):
692+
# Add CPU and RAM usage
693+
process = psutil.Process(os.getpid())
694+
cpu_usage = process.cpu_percent()
695+
ram_usage = round(process.memory_percent(), 2)
696+
ram_real = round(process.memory_info().rss / (1024 ** 2), 2)
697+
698+
embed.add_field(name="CPU", value=f"{cpu_usage}%", inline=True)
699+
embed.add_field(name="RAM", value=f"{ram_usage}%", inline=True)
700+
embed.add_field(name="RAM", value=f"{ram_real} MB", inline=True)
701+
702+
await interaction.followup.send(embed=embed)
700703

701704

702705

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ attrs
66
certifi
77
charset-normalizer
88
colorama
9-
discord.py
9+
discord.py>2.0.0
1010
frozenlist
1111
idna
1212
jsonschema

0 commit comments

Comments
 (0)