-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
50 lines (38 loc) · 1.19 KB
/
bot.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
import os
import sys
import discord
import dotenv
from discord.ext import commands
# Load variables from the .env file.
dotenv.load_dotenv()
# Allowed servers
allowed_servers = [645753006352236544]
# Create a new bot instance with the prefix "!"
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f"successfully logged in as {bot.user}")
@bot.event
async def on_message(msg):
# If the message is from a server that we want to allow, then process it.
if msg.guild.id in allowed_servers:
msg.content = msg.content.lower()
await bot.process_commands(msg)
else:
await msg.channel.send("This bot is not allowed to run in this server.")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, (commands.CommandOnCooldown, commands.UserInputError)):
await ctx.send(str(error))
# Loads all extensions in the cogs folder.
initial_exts = ["cogs.neopixels"]
def main():
token = os.getenv("DISCORD_TOKEN")
if not token:
print("no token specified; make sure you have a .env file with a DISCORD_TOKEN entry")
sys.exit(1)
for ext in initial_exts:
bot.load_extension(ext)
bot.run(token)
if __name__ == "__main__":
main()