-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (47 loc) · 1.76 KB
/
Copy pathmain.py
File metadata and controls
61 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import discord
from discord import Member
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions
import os
import asyncio
from dotenv import load_dotenv
# Tải biến môi trường từ tệp .env
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
client = commands.Bot(command_prefix='!', intents=intents)
class BasicStatement(commands.Cog):
@commands.Cog.listener()
async def on_ready(self):
print('Bot is ready.')
print(f'Logged in as: {self.bot.user}')
print("______________________")
@commands.Cog.listener()
async def on_member_join(self, member):
channel = self.bot.get_channel(os.getenv('CHANNEL_ID'))
await channel.send(f'Hello {member.mention}! Welcome to the server.')
@commands.Cog.listener()
async def on_member_remove(self, member):
channel = self.bot.get_channel(os.getenv('CHANNEL_ID'))
await channel.send(f'Goodbye {member.mention}!')
@commands.command()
async def hello(self, ctx):
print('Hello command received.')
await ctx.send('Lo cc')
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, member: Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f'User {member} has been kicked')
@kick.error
async def kick_error(self, ctx, error):
if isinstance(error, MissingPermissions):
await ctx.send('You do not have permission to kick!')
async def main():
# Add the PlayAudio cog to the bot
await client.add_cog(BasicStatement(client))
# Run the bot
await client.start(os.getenv('DISCORD_TOKEN'))
# Start the bot
asyncio.run(main())