我正在制作一個(gè)Discord Bot,它具有2個(gè)主要功能 - 為只有用戶可以訪問的用戶創(chuàng)建一個(gè)頻道,并讓他們邀請人們進(jìn)入他們的頻道?,F(xiàn)在,第一部分有效,但邀請部分不起作用。首先,下面是允許用戶為自己分配角色的代碼,該角色運(yùn)行良好并添加角色:if message.content.startswith('!!start'): await message.channel.send('Hello {0.author.mention}! Welcome to The Hangout. We are about to setup your account here! Hang on..'.format(message)) print(message.author) overwrites = { message.guild.default_role: discord.PermissionOverwrite(read_messages=False), message.guild.me: discord.PermissionOverwrite(read_messages=True), message.author: discord.PermissionOverwrite(read_messages=True, send_messages=True) } await message.channel.send('What would you like your apartment to be called?') msg = await client.wait_for('message') print(msg.content) apartments = discord.utils.get(message.guild.categories, name='Apartments') print(apartments) channel = await message.guild.create_text_channel(str(msg.content), overwrites=overwrites, category=apartments) await message.channel.send('Done! Next, we will setup a role which people can use to invite you to their apartment by.') await message.channel.send('What would you like your role to be called? (please be sensible, people will use this to invite you.)') msg = await client.wait_for('message') await message.guild.create_role(name=str(msg.content)) role = discord.utils.get(message.guild.roles, name=str(msg.content)) await message.author.add_roles(role) await message.channel.send('Done! You are now setup. In #other, type in !!help to learn how to invite people to your apartment.')以下是處理邀請的代碼:if message.content.startswith('!!invite'): await message.channel.send('Inviting ' + message.content[8:] + "...") role = discord.utils.get(message.guild.roles, name=message.content[8:]) await message.channel.set_permissions(role, send_messages=True, read_messages=True)代碼應(yīng)接受來自用戶(角色)的標(biāo)記,并允許他們訪問用戶的頻道。如何從給定的標(biāo)記中獲取所有用戶的角色,然后篩選出除自定義角色之外的任何其他角色?
Discord.py:如何從用戶輸入的標(biāo)簽中獲取角色?
人到中年有點(diǎn)甜
2022-09-20 17:55:05