#python #discord.py
Вопрос:
Итак, прямо сейчас я пытаюсь сделать так, чтобы конкретная роль не могла говорить по каналу. У меня есть код, который работает, но только ограничивает ctx.guild.default_role
(@everyone) от разговоров.
import discord
import os
from discord.ext import commands
from keep_alive import keep_alive
import asyncio
bot = commands.Bot(command_prefix=' ')
@bot.event
async def on_ready():
print(f'''We have logged in as {bot.user.name}''')
@bot.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_channels=True)
@commands.bot_has_guild_permissions(manage_channels=True)
async def lock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('**An admin/moderator has locked this channel. Please wait for an admin to unlock this channel with ` unlock`.**')
print(f'{ctx.author} locked channel {ctx.channel}')
@bot.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_channels=True)
@commands.bot_has_guild_permissions(manage_channels=True)
async def unlock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=True)
await ctx.send('**An admin/moderator has unlocked this channel with `unlock`.**')
print(f'{ctx.author} unlocked channel {ctx.channel}.')
keep_alive()
bot.run(os.getenv('TOKEN'))
Кто-нибудь, пожалуйста, может мне помочь?
Повторенный вопрос: Мне нужна роль типа «роль крестьянина», которая не сможет говорить, и роль @everyone все еще может говорить на этом канале, когда администратор что-то говорит.
Спасибо людям 🙂
Ответ №1:
Используйте TextChannel.set_permissions и discord.utils.get следующим образом:
await ctx.channel.set_permissions(discord.utils.get(ctx.guild.members, name='Foo'), send_messages=False)
discord.utils.get(ctx.guild.members, name='Foo')
получает роль discord по имени.