Skip to content

Commit d27a246

Browse files
committed
Update for discord.py 2.0.*
1 parent b3f1e83 commit d27a246

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ apt-get -y install python3 python3-pip
1010
``
1111

1212
``
13-
python3 -m pip install discord.py==1.3.4
13+
python3 -m pip install discord.py==2.0.1
1414
``
1515

1616
## HOW TO USE

networkbot.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# DEPENDENCIES
66
# sudo apt-get install python3
77
# sudo apt-get -y install python3-pip
8-
# python3 -m pip install discord.py==1.3.4
8+
# python3 -m pip install discord.py>=2.0.0
99
#
1010
# HOW TO USE
1111
# Go to https://discordapp.com/developers/applications/
@@ -21,6 +21,7 @@
2121
import random
2222
import asyncio
2323
import aiohttp
24+
import discord
2425
import json
2526
from discord.ext import commands
2627
from discord.ext.commands import Bot
@@ -46,12 +47,32 @@
4647
# port used to communicate with the network (your network's RPC port)
4748
PORT = "YOUR_RPC_PORT_GOES_HERE"
4849

50+
# Create bot
51+
class NetworkBot(Bot):
52+
def __init__(self, *args, **kwargs):
53+
super(NetworkBot, self).__init__(*args, **kwargs)
54+
55+
# print list of servers where this bot is active to console
56+
async def list_servers(self):
57+
await self.tree.sync()
58+
while not self.is_closed():
59+
# you can customize the output message(s) below
60+
print("--- NETWORK BOT ONLINE ---")
61+
for guild in self.guilds:
62+
# you can customize the output message(s) below
63+
print('Active servers: ' + str(guild.name))
64+
await asyncio.sleep(600)
65+
66+
async def on_ready(self):
67+
self.loop.create_task(self.list_servers())
68+
4969
# start a bot
50-
client = Bot(command_prefix=BOT_PREFIX, description=description)
70+
intents = discord.Intents.all()
71+
client = NetworkBot(command_prefix=BOT_PREFIX, description=description, intents=intents)
5172

5273
# commmand: &height
5374
# network top block height
54-
@client.command(description="Network top block height.", brief="Blockchain height.")
75+
@client.hybrid_command(description="Network top block height.", brief="Blockchain height.")
5576
async def height(context: commands.Context):
5677
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getheight'
5778
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -63,7 +84,7 @@ async def height(context: commands.Context):
6384

6485
# commmand: &hash
6586
# appx. network hash rate
66-
@client.command(description="Appx. network hash rate.", brief="Network hash rate.")
87+
@client.hybrid_command(description="Appx. network hash rate.", brief="Network hash rate.")
6788
async def hash(context: commands.Context):
6889
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
6990
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -75,7 +96,7 @@ async def hash(context: commands.Context):
7596

7697
# commmand: &diff
7798
# current network difficulty
78-
@client.command(description="Current network difficulty.", brief="Network difficulty.")
99+
@client.hybrid_command(description="Current network difficulty.", brief="Network difficulty.")
79100
async def diff(context: commands.Context):
80101
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
81102
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -87,7 +108,7 @@ async def diff(context: commands.Context):
87108

88109
# commmand: &tx
89110
# total network transactions
90-
@client.command(description="Total network transactions.", brief="Network transactions.")
111+
@client.hybrid_command(description="Total network transactions.", brief="Network transactions.")
91112
async def tx(context: commands.Context):
92113
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
93114
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -99,7 +120,7 @@ async def tx(context: commands.Context):
99120

100121
# commmand: &txpool
101122
# current transactions pool size
102-
@client.command(description="Current transactions pool size.", brief="TX pool size.")
123+
@client.hybrid_command(description="Current transactions pool size.", brief="TX pool size.")
103124
async def txpool(context: commands.Context):
104125
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
105126
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -111,7 +132,7 @@ async def txpool(context: commands.Context):
111132

112133
# commmand: &ver
113134
# current daemon version
114-
@client.command(description="Current daemon version.", brief="Daemon version.")
135+
@client.hybrid_command(description="Current daemon version.", brief="Daemon version.")
115136
async def ver(context: commands.Context):
116137
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
117138
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -123,7 +144,7 @@ async def ver(context: commands.Context):
123144

124145
# commmand: &stats
125146
# key network stats all in one place
126-
@client.command(description="Key network stats all in one place.", brief="Network stats.")
147+
@client.hybrid_command(description="Key network stats all in one place.", brief="Network stats.")
127148
async def stats(context: commands.Context):
128149
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
129150
async with aiohttp.ClientSession() as session: # Async HTTP request
@@ -135,17 +156,4 @@ async def stats(context: commands.Context):
135156
)
136157

137158

138-
# print list of servers where this bot is active to console
139-
async def list_servers():
140-
await client.wait_until_ready()
141-
while not client.is_closed:
142-
# you can customize the output message(s) below
143-
print("--- NETWORK BOT ONLINE ---")
144-
for server in client.servers:
145-
# you can customize the output message(s) below
146-
print('Active servers: ' + str(server.name))
147-
await asyncio.sleep(600)
148-
149-
150-
client.loop.create_task(list_servers())
151159
client.run(TOKEN)

0 commit comments

Comments
 (0)