Skip to content

Commit f21ff97

Browse files
authored
Merge pull request #4 from PyBotDevs/migrate-to-pycord
Migrate client from `discord.py` to PyCord API wrapper
2 parents 3e55d28 + 0df3623 commit f21ff97

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

Diff for: main.py

+53-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datetime
77
import requests
88
import json
9+
from discord import option, ApplicationContext
910
from discord.ext import commands
1011
from discord.ext.commands import *
1112
from discord.ext import tasks
@@ -36,7 +37,7 @@
3637
else: os.system('clear')
3738
owner = '@notsniped'
3839
homedir = os.path.expanduser("~")
39-
client = commands.Bot(command_prefix="+", intents=intents)
40+
client = discord.Bot()
4041
global startTime
4142
startTime = time.time()
4243
client.remove_command('help')
@@ -202,28 +203,43 @@ async def on_message(message):
202203
await client.process_commands(message)
203204

204205
# Commands
205-
@client.command()
206-
async def uptime(ctx):
206+
@client.slash_command(
207+
name="uptime",
208+
description="See the bot's current session uptime."
209+
)
210+
async def uptime(ctx: ApplicationContext):
207211
uptime = str(datetime.timedelta(seconds=int(round(time.time()-startTime))))
208212
await ctx.send(f'This session has been running for **{uptime}**')
209213

210-
@client.command(aliases=['commands'])
211-
async def help(ctx):
212-
emb = discord.Embed(title=f'increment.io Commands', description=f'I am a counting bot who looks for numbers and makes sure that the count doesn\'t get messed up. If you want help on commands or want a more organized view, check https://notsniped.github.io/increment.io/commands\n :warning: This bot is still WIP. Some commands/features may not work as expected.\n\n**Prefix:** ```Main Prefix: +```\n**Information:** ```+help, +ping, +stats, +serverstats,+credits```\n**Counting:** ```+setchannel, +numberonly [on/off], +reactions [on/off], +setnumber [number], +resetcount```', color=theme_color)
214+
@client.slash_command(
215+
name="help",
216+
description="Need help?"
217+
)
218+
async def help(ctx: ApplicationContext):
219+
emb = discord.Embed(title=f'increment.io Commands', description=f'I am a counting bot who looks for numbers and makes sure that the count doesn\'t get messed up. If you want help on commands or want a more organized view, check https://notsniped.github.io/increment.io/commands\n :warning: This bot is still WIP. Some commands/features may not work as expected.\n\n**Prefix:** `/`\n**Information:** ```/help, /ping, /stats, /serverstats, /credits```\n**Counting:** ```/setchannel, /numberonly [on/off], /reactions [on/off], /setnumber [number], /resetcount```', color=theme_color)
213220
await ctx.send(embed = emb)
214221

215-
@client.command(aliases=['pong'])
216-
async def ping(ctx):
222+
@client.slash_command(
223+
name="ping",
224+
description="View the bot latency (in ms)"
225+
)
226+
async def ping(ctx: ApplicationContext):
217227
await ctx.send(f':ping_pong: Pong! In **{round(client.latency * 1000)}ms**.')
218228

219-
@client.command()
220-
async def credits(ctx):
229+
@client.slash_command(
230+
name="credits",
231+
description="View the people behind this bot's development."
232+
)
233+
async def credits(ctx: ApplicationContext):
221234
emb = discord.Embed(title='Bot Credits', description='Owner: <@!738290097170153472>\nHelpers: <@!706697300872921088>, <@!705462972415213588>',color=theme_color)
222235
emb.set_footer(text='increment.io >> https://notsniped.github.io/increment.io')
223236
await ctx.send(embed=emb)
224237

225-
@client.command()
226-
async def serverstats(ctx):
238+
@client.slash_command(
239+
name="serverstats",
240+
description="View counting stats for this server."
241+
)
242+
async def serverstats(ctx: ApplicationContext):
227243
servericon = ctx.guild.icon_url
228244
setchannelstats = countchannel[str(ctx.guild.id)]
229245
setchannelmaxcount = count[setchannelstats]
@@ -234,41 +250,55 @@ async def serverstats(ctx):
234250
await ctx.send(embed = emb12)
235251

236252
# Count Commands
237-
@client.command()
253+
@client.slash_command(
254+
name="setchannel",
255+
description="Sets this channel as the server's counting channel."
256+
)
238257
@commands.has_permissions(administrator = True)
239-
async def setchannel(ctx):
258+
async def setchannel(ctx: ApplicationContext):
240259
try:
241260
countchannel[str(ctx.guild.id)] = ctx.channel.id
242261
savedata()
243262
await ctx.send(f':white_check_mark: <#{channel_to_set}> set as counting channel.')
244263
except: await ctx.send(':x: Unable to set count channel. Try again later.')
245264

246-
@client.command()
265+
@client.slash_command(
266+
name="reactions",
267+
description="Choose whether you want bot reactions enabled or not."
268+
)
269+
@option(name="value", description="Choose a setting value", type=str, choices=["on", "off"])
247270
@commands.has_permissions(administrator = True)
248-
async def reactions(ctx, setting:str):
249-
if setting == 'on':
271+
async def reactions(ctx: ApplicationContext, value: str):
272+
if value == 'on':
250273
if autoreactions[str(ctx.guild.id)] == 1: await ctx.send(':warning: This feature is already enabled.')
251274
else:
252275
autoreactions[str(ctx.guild.id)] = 1
253276
savedata()
254277
await ctx.send(f':white_check_mark: Turned **on** count reactions.')
255-
elif setting == 'off':
278+
elif value == 'off':
256279
if autoreactions[str(ctx.guild.id)] == 0: await ctx.send(':warning: This feature is already disabled')
257280
else:
258281
autoreactions[str(ctx.guild.id)] = 0
259282
savedata()
260283
await ctx.send(f':white_check_mark: Turned **off** count reactions.')
261284
else: await ctx.send(f'\'{setting}\' is not a valid option. You can choose between `on` and `off`')
262285

263-
@client.command(aliases=['setnum'])
264-
async def setnumber(ctx, arg1:int):
265-
if arg1 < 1: raise(discord.ext.commands.BadArgument)
286+
@client.slash_command(
287+
name="setnumber",
288+
description="Set the current count to a new value."
289+
)
290+
@option(name="new_count", description="What do you want to set the count to?", type=int)
291+
async def setnumber(ctx: ApplicationContext, new_count: int):
292+
if new_count < 1: raise(discord.ext.commands.BadArgument)
266293
else:
267-
count[str(ctx.channel.id)] = arg1
294+
count[str(ctx.channel.id)] = new_count
268295
savedata()
269296
await ctx.reply(f':white_check_mark: Count set to `{count[str(ctx.channel.id)]}`')
270297

271-
@client.command(aliases=['resetnumber', 'reset', 'resetnum'])
298+
@client.slash_command(
299+
name="resetcount",
300+
description="Reset the current count."
301+
)
272302
async def resetcount(ctx):
273303
count[str(ctx.channel.id)] = 1
274304
savedata()

Diff for: pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.poetry]
2+
name = "increment-io"
3+
version = "v2023.723.0"
4+
description = "An extremely simple, yet functional counting Discord bot."
5+
authors = ["snipe_blaze <[email protected]>"]
6+
license = "GPL-3.0"
7+
readme = "README.md"
8+
packages = [{include = "increment_io"}]
9+
10+
[tool.poetry.dependencies]
11+
python = "^3.11"
12+
py-cord = "^2.4.1"
13+
14+
15+
[build-system]
16+
requires = ["poetry-core"]
17+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)