Package Concepts with code snippets #8
Replies: 8 comments 24 replies
-
Simplest commandThe command syntax will be very similar to the original discordpy one. @command('my_command')
async def ping() -> str:
return 'pong' |
Beta Was this translation helpful? Give feedback.
-
A @command('my_command')
async def ping(ctx: Context) -> Message:
return Message(
'pong',
replied_from=ctx.message
) |
Beta Was this translation helpful? Give feedback.
-
WatchersWatcher objects can be return to have an even trigger which allow to def check(ctx: Context, m: Message):
return m.author == ctx.author
@command('something')
async def something() -> Tuple[Embed, Watcher]:
...
return an_embed, watcher(
'button_click', check=check, something_else
)
@watcher
async def something_else(ctx: Context) -> Embed:
... |
Beta Was this translation helpful? Give feedback.
-
Arguments |
Beta Was this translation helpful? Give feedback.
-
Current for commands we have this @command('my_command')
async def ping(self, number: int):
return f'Pong! Your number is {number}' This work fine for now but what if we want to send multiple responses? The current suggestions are either creating a watcher or bringing back @command('my_command')
async def ping(self, number: int):
yield 'some long message`
yield Embed(...)
if some_condition_that_has_changed():
yield 'good job'
else:
yield 'meh' |
Beta Was this translation helpful? Give feedback.
-
Shorthands for some methods Instead of doing this channel.name = "pincer" Similarly, channel.delete() # from this
del channel # to this |
Beta Was this translation helpful? Give feedback.
-
Implementation of subcommands and groupsI suggest that we use nesting and the return value from new decorators. Sample Code (adapted from the discord docs): from pincer import command, group, subcommand, User
class ModBot(Client)
@command(group=True)
async def permissions(self):
@group(name="user", description="Get or edit permissions for a user")
async def user_group(self):
@subcommand(description="Get permissions for a user")
async def get(self, ctx, user: User):
member = GuildMember.from_id(self, ctx.guild_id, user.id)
return str(member.permissions)
@subcommand(description="Edit permissions for a user")
async def edit(self, ctx, user: User, role: Role):
guild = await self.get_guild(ctx.guild_id)
await guild.modify_member(_id=user.id, roles=[role.id]):
return "Modified roles"
return [get, edit]
@subcommand(description="Clear all roles from a user")
async def clear(self, ctx, user: User):
guild = await self.get_guild(ctx.guild_id)
await guild.modify_member(_id=user.id, roles=[])
return "Cleared all roles"
return [user_group, clear] |
Beta Was this translation helpful? Give feedback.
-
I believe if the focus is on the from pincer import command, group, subcommand, User
class ModBot(Client)
@subcommand(description="Get permissions for a user")
async def get(self, ctx, user: User):
member = GuildMember.from_id(self, ctx.guild_id, user.id)
return str(member.permissions)
@subcommand(description="Edit permissions for a user")
async def edit(self, ctx, user: User, role: Role):
guild = await self.get_guild(ctx.guild_id)
await guild.modify_member(_id=user.id, roles=[role.id]):
return "Modified roles"
@subcommand(description="Clear all roles from a user")
async def clear(self, ctx, user: User):
guild = await self.get_guild(ctx.guild_id)
await guild.modify_member(_id=user.id, roles=[])
return "Cleared all roles"
@group(name="user", description="Get or edit permissions for a user")
async def user_group(self):
return [selr.get, self.edit]
@command(group=True)
async def permissions(self):
return [self.user_group, self.clear] |
Beta Was this translation helpful? Give feedback.
-
This discussion is meant to allow everyone to propose and share their idea on what some features could looks like (and why) using code snippets.
Beta Was this translation helpful? Give feedback.
All reactions