-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
62 lines (52 loc) · 2.02 KB
/
bot.py
File metadata and controls
62 lines (52 loc) · 2.02 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
import os
import discord
import random
import requests
from dotenv import load_dotenv
from facts import facts
from bs4 import BeautifulSoup
# replace the token variable with your own bot token to test the bot out
load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')
client = discord.Client(intents=discord.Intents.all())
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord')
@client.event
async def on_message(message):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel})')
if message.author == client.user:
return
if user_message.lower() == '!nerd':
await message.channel.send('Commands:\n!fact\n!math\n!wiki')
return
elif user_message.lower() == '!fact':
await message.channel.send('Fun fact, ' + facts[random.randint(0, 99)])
return
elif user_message.lower() == '!math':
equation = ''
amount_of_nums = random.randint(2, 5)
for i in range(amount_of_nums):
equation += str(random.randint(1, 100))
operator_choice = random.randint(0,3)
if i + 1 != amount_of_nums:
if operator_choice == 0:
equation += ' + '
elif operator_choice == 1:
equation += ' - '
elif operator_choice == 2:
equation += ' × '
elif operator_choice == 3:
equation += ' ÷ '
await message.channel.send('Your question is: ' + equation)
return
elif user_message.lower() == '!wiki':
wiki_url = requests.get("https://en.wikipedia.org/wiki/Special:Random")
soup = BeautifulSoup(wiki_url.content, "html.parser")
title = soup.find(class_="firstHeading").text
await message.channel.send('Here is a wiki article about ' + title + ': https://en.wikipedia.org/wiki/' + title.replace(' ', '_'))
return
client.run(TOKEN)