forked from malikv32201/Discordbot.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
77 lines (59 loc) · 2.25 KB
/
bot.py
File metadata and controls
77 lines (59 loc) · 2.25 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 random
import asyncio
import aiohttp
import json
from discord import Game
from discord.ext.commands import Bot
BOT_PREFIX = ("?", "!")
TOKEN = '#insert own token code here'
client = Bot(command_prefix=BOT_PREFIX)
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!help'):
msg = 'Hello {0.author.mention} \n Currently available commands are: \n 1.8ball\n 2.bitcoin\n 3.square'.format(message)
await client.send_message(message.channel, msg)
@client.command(name='8ball',
description="Answers a yes/no question.",
brief="Answers from the beyond.",
aliases=['eight_ball', 'eightball', '8-ball'],
pass_context=True)
async def eight_ball(context):
possible_responses = [
'That is a resounding no',
'It is not looking likely',
'Too hard to tell',
'It is quite possible',
'Definitely',
]
await client.say(random.choice(possible_responses) + ", " + context.message.author.mention)
@client.command()
async def square(number):
squared_value = int(number) * int(number)
await client.say(str(number) + " squared is " + str(squared_value))
@client.event
async def on_ready():
await client.change_presence(game=Game(name="!help"))
print("Logged in as " + client.user.name)
@client.command()
async def bitcoin():
url = 'https://api.coindesk.com/v1/bpi/currentprice/BTC.json'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
await client.say("Bitcoin price is: $" + response['bpi']['USD']['rate'])
async def list_servers():
await client.wait_until_ready()
while not client.is_closed:
print("Current servers:")
for server in client.servers:
print(server.name)
await asyncio.sleep(600)
client.loop.create_task(list_servers())
client.run(TOKEN)