Discord.py Упоминание роли после выполнения команды - PullRequest
0 голосов
/ 29 апреля 2020

Привет, я хотел бы, чтобы роль людей была упомянута после добавления / удаления в очереди.

Пример:

! Addme

Джо Блоггс из Роли {клан } Был добавлен в очередь

    @commands.command(pass_context=True)
    async def addme(self, ctx):
        ''': Add yourself to the queue!'''
        author = ctx.message.author
        if self.qtoggle:
            if author.id not in self.queue:
                self.queue.append(author.id)
                await ctx.send('you have been added to the Tablet Crafting Queue.')
            else:
                await ctx.send('you are already in the Tablet Crafting Queue!')
        else:
                await ctx.send('The Tablet Crafting Queue is closed.')

    @commands.command(pass_context=True)
    async def removeme(self, ctx):
        ''': Remove yourself from the queue'''
        author = ctx.message.author
        if author.id in self.queue:
            self.queue.remove(author.id)
            await ctx.send('you have been removed from the Tablet Crafting Queue.')
        else:
            await ctx.send('you were not in the Tablet Crafting Queue.')

    @commands.command(name='queue', pass_context=True)
    async def _queue(self, ctx):
        ''': See who's up next!'''
        server = ctx.message.guild
        message = ''
        for place, member_id in enumerate(self.queue):
            member = discord.utils.get(server.members, id=member_id)
            message += f'**#{place+1}** : {member.mention} : {role.mention}\n'
        if message != '':
            await ctx.send(message)
        else:
            await ctx.send('Tablet Crafting Queue is empty')

1 Ответ

0 голосов
/ 29 апреля 2020

Обратите внимание, что «участник» может иметь несколько «ролей» и что «участник» представляет учетную запись и может принадлежать нескольким «гильдиям». Как таковой, кажется, нет способа легко получить роль члена в гильдии (по уважительной причине).

Это неэффективно, но вам, возможно, просто придется поискать все роли Гильдия ищет высшую роль члена.

# pseudocode
for role in guild.roles:
    if member in role.members:
        role_title = role.name

Документы гильдии - Изучите роль Ролевые документы - Изучите участников

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...