-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
77 lines (51 loc) · 2.03 KB
/
Copy pathbot.py
File metadata and controls
77 lines (51 loc) · 2.03 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os , nextcord , logging , json ,datetime, asyncio
from dotenv import load_dotenv
from nextcord.ext import commands
# Local code
class Scam_Protector(commands.Cog):
def __init__(self, bot):
self.bot = bot
# Greetings
@commands.Cog.listener()
async def on_ready(self):
await bot.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.watching, name='for scam links'))
print(f'Logged in as {self.bot.user} ({self.bot.user.id})')
# Reconnect
@commands.Cog.listener()
async def on_resumed(self):
print('Bot has reconnected!')
# Error Handlers
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
# Uncomment line 26 for printing debug
# await ctx.send(error)
# Unknown command
if isinstance(error, commands.CommandNotFound):
await ctx.send('Invalid Command!')
# Bot does not have permission
elif isinstance(error, commands.MissingPermissions):
await ctx.send('Bot Permission Missing!')
# Gateway intents
intents = nextcord.Intents.default()
intents.members = True
intents.presences = True
intents.messages = True
# Bot prefix
bot = commands.Bot(command_prefix=commands.when_mentioned_or('sp'),
description='Scam Protecton Bot', intents=intents)
# Logging
logger = logging.getLogger('nextcord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='nextcord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
# Loading data from .env file
load_dotenv()
token = os.getenv('TOKEN')
if __name__ == '__main__':
# Load extension
for filename in os.listdir('./commands'):
if filename.endswith('.py'):
bot.load_extension(f'commands.{filename[: -3]}')
bot.add_cog(Scam_Protector(bot))
bot.run(token, reconnect=True)