Gabeczkag commited on
Commit
9bf4e97
·
1 Parent(s): 1add7fb

Slash commands / moderation v3

Browse files
Files changed (2) hide show
  1. au.version +1 -1
  2. bot.py +78 -85
au.version CHANGED
@@ -1 +1 @@
1
- 2
 
1
+ 3
bot.py CHANGED
@@ -1,7 +1,6 @@
1
  import discord
2
- from discord.ext import commands
3
  import os
4
- import asyncio
5
  from datetime import timedelta
6
  from dotenv import load_dotenv
7
 
@@ -13,108 +12,102 @@ intents = discord.Intents.default()
13
  intents.message_content = True
14
  intents.members = True
15
 
16
- bot = commands.Bot(command_prefix="!", intents=intents)
17
 
 
 
 
 
18
 
19
- @bot.event
20
- async def on_ready():
21
- print(f"Zalogowano jako {bot.user}")
22
 
 
 
23
 
24
- @bot.command()
25
- async def ping(ctx):
26
- await ctx.send("Pong!")
27
 
 
28
 
29
- @bot.command()
30
- async def hello(ctx):
31
- await ctx.send(f"Cześć {ctx.author.mention}!")
32
 
 
 
 
33
 
34
- @bot.command()
35
- @commands.has_permissions(kick_members=True)
36
- async def kick(ctx, member: discord.Member, *, reason="Nie podano powodu"):
 
 
 
 
 
 
 
37
  await member.kick(reason=reason)
38
- await ctx.send(f"👍 Wyrzucono {member.mention}. Powód: {reason}")
39
 
40
 
41
- @bot.command()
42
- @commands.has_permissions(ban_members=True)
43
- async def ban(ctx, member: discord.Member, *, reason="Nie podano powodu"):
 
44
  await member.ban(reason=reason)
45
- await ctx.send(f"👍 Zbanowano {member.mention}. Powód: {reason}")
46
-
47
-
48
- @bot.command()
49
- @commands.has_permissions(ban_members=True)
50
- async def unban(ctx, *, member):
51
- banned = [u async for u in ctx.guild.bans()]
52
- name, discrim = member.split("#")
53
- user = next((u for u in banned if u.user.name == name and u.user.discriminator == discrim), None)
54
- if user:
55
- await ctx.guild.unban(user.user)
56
- await ctx.send(f"👍 Odbanowano {user.user}")
 
57
  else:
58
- await ctx.send("❌ Nie znaleziono użytkownika")
59
 
60
 
61
- @bot.command()
62
- @commands.has_permissions(moderate_members=True)
63
- async def timeout(ctx, member: discord.Member, minutes: int, *, reason="Nie podano powodu"):
 
64
  await member.timeout(discord.utils.utcnow() + timedelta(minutes=minutes), reason=reason)
65
- await ctx.send(f"👍 Wyciszono {member.mention} na {minutes} min. Powód: {reason}")
66
 
67
 
68
- @bot.command()
69
- @commands.has_permissions(moderate_members=True)
70
- async def untimeout(ctx, member: discord.Member):
 
71
  await member.timeout(None)
72
- await ctx.send(f"👍 Cofnięto wyciszenie {member.mention}")
73
-
74
-
75
- @bot.command()
76
- @commands.has_permissions(manage_messages=True)
77
- async def clear(ctx, amount: int):
78
- await ctx.channel.purge(limit=amount + 1)
79
- await ctx.send(f"👍 Usunięto {amount} wiadomości", delete_after=5)
80
-
81
-
82
- @bot.command()
83
- @commands.has_permissions(manage_channels=True)
84
- async def lock(ctx, channel: discord.TextChannel = None):
85
- channel = channel or ctx.channel
86
- await channel.set_permissions(ctx.guild.default_role, send_messages=False)
87
- await ctx.send(f"🔒 Zablokowano {channel.mention}")
88
-
89
-
90
- @bot.command()
91
- @commands.has_permissions(manage_channels=True)
92
- async def unlock(ctx, channel: discord.TextChannel = None):
93
- channel = channel or ctx.channel
94
- await channel.set_permissions(ctx.guild.default_role, send_messages=True)
95
- await ctx.send(f"🔓 Odblokowano {channel.mention}")
96
-
97
-
98
- @clear.error
99
- @kick.error
100
- @ban.error
101
- @unban.error
102
- @timeout.error
103
- @untimeout.error
104
- @lock.error
105
- @unlock.error
106
- async def mod_error(ctx, error):
107
- if isinstance(error, commands.MissingPermissions):
108
- await ctx.send("❌ Nie masz uprawnień do tej komendy")
109
- elif isinstance(error, commands.BadArgument):
110
- await ctx.send("❌ Nieprawidłowy argument. Sprawdź składnię")
111
- else:
112
- await ctx.send(f"❌ Błąd: {error}")
113
 
 
 
 
 
 
 
 
114
 
115
- async def start_bot():
116
- async with bot:
117
- await bot.start(TOKEN)
118
 
119
- if __name__ == "__main__":
120
- asyncio.run(start_bot())
 
1
  import discord
2
+ from discord import app_commands
3
  import os
 
4
  from datetime import timedelta
5
  from dotenv import load_dotenv
6
 
 
12
  intents.message_content = True
13
  intents.members = True
14
 
 
15
 
16
+ class BotDC(discord.Client):
17
+ def __init__(self):
18
+ super().__init__(intents=intents)
19
+ self.tree = app_commands.CommandTree(self)
20
 
21
+ async def setup_hook(self):
22
+ await self.tree.sync()
 
23
 
24
+ async def on_ready(self):
25
+ print(f"Zalogowano jako {self.user}")
26
 
 
 
 
27
 
28
+ bot = BotDC()
29
 
 
 
 
30
 
31
+ @bot.tree.command(name="ping", description="Sprawdza czy bot odpowiada")
32
+ async def ping(interaction: discord.Interaction):
33
+ await interaction.response.send_message("Pong!")
34
 
35
+
36
+ @bot.tree.command(name="hello", description="Wita użytkownika")
37
+ async def hello(interaction: discord.Interaction):
38
+ await interaction.response.send_message(f"Cześć {interaction.user.mention}!")
39
+
40
+
41
+ @bot.tree.command(name="kick", description="Wyrzuca użytkownika")
42
+ @app_commands.describe(member="Użytkownik do wyrzucenia", reason="Powód")
43
+ @app_commands.default_permissions(kick_members=True)
44
+ async def kick(interaction: discord.Interaction, member: discord.Member, reason: str = "Nie podano powodu"):
45
  await member.kick(reason=reason)
46
+ await interaction.response.send_message(f"👍 Wyrzucono {member.mention}. Powód: {reason}")
47
 
48
 
49
+ @bot.tree.command(name="ban", description="Banuje użytkownika")
50
+ @app_commands.describe(member="Użytkownik do zbanowania", reason="Powód")
51
+ @app_commands.default_permissions(ban_members=True)
52
+ async def ban(interaction: discord.Interaction, member: discord.Member, reason: str = "Nie podano powodu"):
53
  await member.ban(reason=reason)
54
+ await interaction.response.send_message(f"👍 Zbanowano {member.mention}. Powód: {reason}")
55
+
56
+
57
+ @bot.tree.command(name="unban", description="Odbanowuje użytkownika")
58
+ @app_commands.describe(user="Nazwa użytkownika (np. user#1234)")
59
+ @app_commands.default_permissions(ban_members=True)
60
+ async def unban(interaction: discord.Interaction, user: str):
61
+ banned = [u async for u in interaction.guild.bans()]
62
+ name, discrim = user.split("#")
63
+ entry = next((u for u in banned if u.user.name == name and u.user.discriminator == discrim), None)
64
+ if entry:
65
+ await interaction.guild.unban(entry.user)
66
+ await interaction.response.send_message(f"👍 Odbanowano {entry.user}")
67
  else:
68
+ await interaction.response.send_message("❌ Nie znaleziono użytkownika")
69
 
70
 
71
+ @bot.tree.command(name="timeout", description="Wycisza użytkownika na X minut")
72
+ @app_commands.describe(member="Użytkownik", minutes="Liczba minut", reason="Powód")
73
+ @app_commands.default_permissions(moderate_members=True)
74
+ async def timeout(interaction: discord.Interaction, member: discord.Member, minutes: int, reason: str = "Nie podano powodu"):
75
  await member.timeout(discord.utils.utcnow() + timedelta(minutes=minutes), reason=reason)
76
+ await interaction.response.send_message(f"👍 Wyciszono {member.mention} na {minutes} min. Powód: {reason}")
77
 
78
 
79
+ @bot.tree.command(name="untimeout", description="Cofa wyciszenie")
80
+ @app_commands.describe(member="Użytkownik")
81
+ @app_commands.default_permissions(moderate_members=True)
82
+ async def untimeout(interaction: discord.Interaction, member: discord.Member):
83
  await member.timeout(None)
84
+ await interaction.response.send_message(f"👍 Cofnięto wyciszenie {member.mention}")
85
+
86
+
87
+ @bot.tree.command(name="clear", description="Usuwa wiadomości")
88
+ @app_commands.describe(amount="Liczba wiadomości do usunięcia")
89
+ @app_commands.default_permissions(manage_messages=True)
90
+ async def clear(interaction: discord.Interaction, amount: int):
91
+ await interaction.channel.purge(limit=amount)
92
+ await interaction.response.send_message(f"👍 Usunięto {amount} wiadomości", delete_after=5)
93
+
94
+
95
+ @bot.tree.command(name="lock", description="Blokuje kanał")
96
+ @app_commands.describe(channel="Kanał do zablokowania (opcjonalnie)")
97
+ @app_commands.default_permissions(manage_channels=True)
98
+ async def lock(interaction: discord.Interaction, channel: discord.TextChannel = None):
99
+ channel = channel or interaction.channel
100
+ await channel.set_permissions(interaction.guild.default_role, send_messages=False)
101
+ await interaction.response.send_message(f"🔒 Zablokowano {channel.mention}")
102
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ @bot.tree.command(name="unlock", description="Odblokowuje kanał")
105
+ @app_commands.describe(channel="Kanał do odblokowania (opcjonalnie)")
106
+ @app_commands.default_permissions(manage_channels=True)
107
+ async def unlock(interaction: discord.Interaction, channel: discord.TextChannel = None):
108
+ channel = channel or interaction.channel
109
+ await channel.set_permissions(interaction.guild.default_role, send_messages=True)
110
+ await interaction.response.send_message(f"🔓 Odblokowano {channel.mention}")
111
 
 
 
 
112
 
113
+ bot.run(TOKEN)