-
Notifications
You must be signed in to change notification settings - Fork 2
/
discord_main.py
93 lines (76 loc) · 3.45 KB
/
discord_main.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# imports
import datetime
from dotenv import load_dotenv
import discord
from discord.ext import commands
import os
# Loading env variables
load_dotenv('.env')
def get_prefix():
with open('assets/text/prefix', 'r') as file:
return file.readline()[0]
class CustomHelpCommand(commands.HelpCommand):
def __init__(self):
super().__init__()
def get_ending_note(self):
command_name = self.invoked_with
return "Type {0}{1} <command/category> for more information | [Optional Arg], <Required Arg>".format(
get_prefix(), command_name)
async def send_bot_help(self, mapping):
help_command = discord.Embed(
title='Help is on the way',
description=f'Heard you needed help! Here are all the commands you can access. {client.description}',
colour=discord.Colour.blurple(),
)
for cog in mapping:
if cog is not None:
cog_name = cog.qualified_name
else:
cog_name = 'Normie Commands'
filtered = await self.filter_commands([command for command in mapping[cog]])
value = os.linesep.join([("> " + command.name.title()) for command in filtered])
if len(value) > 1:
help_command.add_field(name=cog_name, value=value)
help_command.set_footer(text=self.get_ending_note())
await self.get_destination().send(embed=help_command)
return await super(CustomHelpCommand, self).send_bot_help(mapping)
async def send_cog_help(self, cog):
cog_embed = discord.Embed(
title=cog.qualified_name,
colour=discord.Colour.blurple(),
timestamp=datetime.datetime.utcnow()
)
filtered = await self.filter_commands([command for command in cog.get_commands()], sort=True)
for command in filtered:
cog_embed.add_field(name=command.name.title(), value=command.help, inline=False)
cog_embed.set_footer(text=self.get_ending_note())
await self.get_destination().send(embed=cog_embed)
return await super(CustomHelpCommand, self).send_cog_help(cog)
async def send_group_help(self, group): # Don't Need
return await super(CustomHelpCommand, self).send_group_help(group)
async def send_command_help(self, command):
ctx = self.context
if len("|".join(command.aliases)) > 0:
base = f'{get_prefix()}[{command.name}|{"|".join(command.aliases)}]'
else:
base = f'{get_prefix()}[{command.name}]'
syntax = f'```{base} {command.signature}```'
command_embed = discord.Embed(
title=command.name.title(),
description=command.help + '\n' + syntax,
colour=discord.Colour.blurple(),
timestamp=datetime.datetime.utcnow()
)
command_embed.set_footer(text=self.get_ending_note())
await self.get_destination().send(embed=command_embed)
return await super(CustomHelpCommand, self).send_command_help(command)
# setting up indents
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='!', intents=intents, case_insensitive=True,
help_command=CustomHelpCommand())
async def on_ready():
await client.change_presence(
activity=discord.Activity(type=discord.ActivityType.watching, name="the latest developments in tech"))
print('Bot is ready')
client.run(str(os.getenv('DISCORD_TOKEN')))