-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
91 lines (75 loc) · 3.44 KB
/
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
import os
import sys
import colorama
from dotenv import load_dotenv
import hikari
import lightbulb
bot_commands = ['add', 'ban', 'hello', 'help', 'kick']
load_dotenv()
token = os.getenv("TOKEN")
server_id_tuple = os.getenv("SERVER_ID").split(",")
bot = lightbulb.BotApp(
token=token,
default_enabled_guilds=server_id_tuple
)
@bot.listen(hikari.StartedEvent)
async def on_started(event):
print("Bot has has connected to Discord!")
@bot.command
@lightbulb.command('hello', 'Says hello!')
@lightbulb.implements(lightbulb.SlashCommand)
async def hello(ctx):
await ctx.respond(f'Hello!')
print(colorama.Fore.LIGHTCYAN_EX + "Hello command sent" + colorama.Fore.RESET)
@bot.command
@lightbulb.command('help', 'Sends a list of commands!')
@lightbulb.implements(lightbulb.SlashCommand)
async def help(ctx):
sorted_commands = sorted(bot_commands)
await ctx.respond(f'{sorted_commands}')
print(colorama.Fore.LIGHTCYAN_EX + "Help command sent" + colorama.Fore.RESET)
print(colorama.Fore.WHITE + f"{sorted_commands}" + colorama.Fore.RESET)
@bot.command
@lightbulb.option('num1', 'First number', type=int)
@lightbulb.option('num2', 'Second number', type=int)
@lightbulb.command('add', 'Sums two numbers!')
@lightbulb.implements(lightbulb.SlashCommand)
async def calc(ctx):
await ctx.respond(f'Result is: {ctx.options.num1 + ctx.options.num2}')
print(colorama.Fore.LIGHTCYAN_EX + "Calc command sent" + colorama.Fore.RESET)
print(colorama.Fore.WHITE + f'Result is: {ctx.options.num1 + ctx.options.num2}' + colorama.Fore.RESET)
@bot.command()
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.BAN_MEMBERS))
@lightbulb.option("reason", "Reason for the ban", required=False)
@lightbulb.option("user", "The user to ban.", type=hikari.User)
@lightbulb.command("ban", "Ban a user from the server.")
@lightbulb.implements(lightbulb.SlashCommand)
async def ban(ctx: lightbulb.SlashContext) -> None:
if not ctx.guild_id:
await ctx.respond("This command can only be used in a guild.")
return
await ctx.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
await ctx.app.rest.ban_user(ctx.guild_id, ctx.options.user.id, reason=ctx.options.reason or hikari.UNDEFINED)
await ctx.respond(f"Banned {ctx.options.user.mention}.\n**Reason:** {ctx.options.reason or 'No reason provided.'}")
print(colorama.Fore.LIGHTCYAN_EX + "User has been banned!" + colorama.Fore.RESET)
@bot.command()
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.KICK_MEMBERS))
@lightbulb.option("reason", "Reason for the kick", required=False)
@lightbulb.option("user", "The user to kick.", type=hikari.User)
@lightbulb.command("kick", "Kick a user from the server.")
@lightbulb.implements(lightbulb.SlashCommand)
async def kick(ctx: lightbulb.SlashContext) -> None:
if not ctx.guild_id:
await ctx.respond("This command can only be used in a guild.")
return
await ctx.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
await ctx.app.rest.kick_user(ctx.guild_id, ctx.options.user.id, reason=ctx.options.reason or hikari.UNDEFINED)
await ctx.respond(f"Kicked {ctx.options.user.mention}.\n**Reason:** {ctx.options.reason or 'No reason provided.'}")
print(colorama.Fore.GREEN + "User has been kicked!" + colorama.Fore.RESET)
if __name__ == "__main__":
try:
bot.run()
except Exception as e:
print(f"Exception caught: {e}")
print("Exiting...")
sys.exit(0)