我对这些命令有一些问题。 在第一种情况下,我无法使其显示为错误消息,即通道当前已被阻止(我不知道如何执行此操作,但我需要它以避免将来出现错误)
代码:
@client.command(aliases=["Lock","LOCK","blocco","Blocco","BLOCCO"])
@commands.has_any_role('Triumvirato')
async def lock(ctx, *,arg="Motivo non specificato"):
channel_ability_mention = ctx.channel.mention
channel_ability_name = ctx.channel.name
embed = discord.Embed(
color=0xa61022
)
if oof == off: #here I put something at random because I don't know how to form the if
embed.set_author(
name=f'{channel_ability_name} è attualmente bloccato',
icon_url=f'https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
embed.set_footer(text=f'Motivo: {arg}')
await ctx.send(embed=embed, delete_after=10.0)
return
在第二种情况下,我不知道如何删除用户权限(这将暂时看到templock也将被那些没有管理权限的人使用)
代码:
async def templock(ctx, seconds = 0, *,arg="Motivo non specificato"):
channel_ability_mention = ctx.channel.mention
channel_ability_name = ctx.channel.name
triumvirato = discord.utils.get(ctx.guild.roles, id=690951634183782461)
co_triumvirato = discord.utils.get(ctx.guild.roles, id=690954867346243624)
presidente = discord.utils.get(ctx.guild.roles, id=690956686147453048)
moderatore = discord.utils.get(ctx.guild.roles, id=700353561392971877)
embed = discord.Embed(
color=0xa61022
)
if not seconds:
embed.set_author(
name="Per favore specifica il tempo!",
icon_url="https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png"
)
await ctx.send(embed=embed, delete_after=10.0)
return
if triumvirato in ctx.author.roles:
if seconds > 600:
embed.set_author(
name="Hai superato il limite stabilito per i Triumviri!",
icon_url="https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png"
)
await ctx.send(embed=embed, delete_after=10.0)
return
embed = discord.Embed(
color=0x03c03c
)
if seconds == 1:
embed.set_author(
name=f'Hai bloccato {channel_ability_name} per un secondo',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
await ctx.send(embed=embed, delete_after=10.0)
await ctx.channel.set_permissions(ctx.author, send_messages=True)
await ctx.channel.set_permissions(ctx.guild.default_role, manage_channels=False, manage_permissions=False, read_messages=False, send_messages=False, manage_messages=False, add_reactions=False)
embed = discord.Embed(
color=0xFFD000
)
embed.set_author(
name=f'{ctx.author._user} ha bloccato il canale {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
embed.add_field(
name='Bloccato da:',
value=f'{ctx.author._user}',
inline=True
)
embed.add_field(
name='Canale:',
value=f'{channel_ability_mention}',
inline=True
)
embed.add_field(
name='Durata:',
value=f'{seconds}s',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
if seconds > 1:
embed.set_author(
name=f'Hai bloccato {channel_ability_name} per {seconds} secondi',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
await ctx.send(embed=embed, delete_after=10.0)
await ctx.channel.set_permissions(ctx.guild.default_role, manage_channels=False, manage_permissions=False, read_messages=False, send_messages=False, manage_messages=False, add_reactions=False)
embed = discord.Embed(
color=0xFFD000
)
embed.set_author(
name=f'{ctx.author._user} ha bloccato il canale {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
embed.add_field(
name='Bloccato da:',
value=f'{ctx.author._user}',
inline=True
)
embed.add_field(
name='Canale:',
value=f'{channel_ability_mention}',
inline=True
)
embed.add_field(
name='Durata:',
value=f'{seconds}s',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
await asyncio.sleep(seconds)
embed = discord.Embed(
color=0x03c03c
)
embed.set_author(
name=f'Hai sbloccato {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
await ctx.send(embed=embed, delete_after=10.0)
await ctx.channel.set_permissions(ctx.author, ) #I don't think set_permissions should stay here as I want the user permissions to disappear
await ctx.channel.set_permissions(ctx.guild.default_role, manage_channels=False, manage_permissions=False, read_messages=False, manage_messages=False)
embed = discord.Embed(
color=0xFFD000
)
embed.set_author(
name=f'{client.user} ha sbloccato il canale {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.add_field(
name='Sbloccato da:',
value=f'{client.user}',
inline=True
)
embed.add_field(
name='Canale:',
value=f'{channel_ability_mention}',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
return
编辑:我试着同时执行锁定和解锁两个命令,但如果我执行这两个命令中的一个,另一个命令则无效。我不知道如何解决
#lock [COMPLETATO]
@client.command(aliases=["Lock","LOCK","blocco","Blocco","BLOCCO"])
@commands.has_any_role('Triumvirato')
async def lock(ctx, *,arg="Motivo non specificato"):
channel_ability_mention = ctx.channel.mention
channel_ability_name = ctx.channel.name
embed = discord.Embed(
color=0xa61022
)
try:
temp = locked_channels[ctx.channel.id]
except:
locked_channels[ctx.channel.id] = True
embed = discord.Embed(
color=0x03c03c
)
embed.set_author(
name=f'Hai bloccato {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
await ctx.send(embed=embed, delete_after=10.0)
await ctx.channel.set_permissions(ctx.guild.default_role, manage_channels=False, manage_permissions=False, read_messages=False, send_messages=False, manage_messages=False, add_reactions=False)
embed = discord.Embed(
color=0xFFD000
)
embed.set_author(
name=f'{ctx.author._user} ha sbloccato il canale {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
embed.add_field(
name='Bloccato da:',
value=f'{ctx.author._user}',
inline=True
)
embed.add_field(
name='Canale:',
value=f'{channel_ability_mention}',
inline=True
)
embed.add_field(
name='Durata:',
value=f'∞',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
return
else:
embed.set_author(
name=f'{channel_ability_name} è attualmente bloccato',
icon_url=f'https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
await ctx.send(embed=embed, delete_after=10.0)
return
@lock.error
async def lock_error(ctx, error):
embed=discord.Embed(
color=0xa61022
)
if isinstance(error, commands.CheckFailure):
embed.set_author(
name="Non ti è permesso bloccare il canale!",
icon_url='https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
await ctx.send(embed=embed, delete_after=10.0)
return
#unlock [MANCA : MESSAGGIO ERRORE CANALE GIA' SBLOCCATO]
@client.command(aliases=["Unock","UNLOCK","ul","Ul","UL","sblocco","Sblocco","SBLOCCO"])
@commands.has_any_role('Triumvirato')
async def unlock(ctx):
channel_ability_mention = ctx.channel.mention
channel_ability_name = ctx.channel.name
embed = discord.Embed(
color=0xa61022
)
try:
temp = locked_channels[ctx.channel.id]
except:
locked_channels[ctx.channel.id] = False
embed = discord.Embed(
color=0x03c03c
)
embed.set_author(
name=f'Hai sbloccato {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
await ctx.send(embed=embed, delete_after=10.0)
await ctx.channel.set_permissions(ctx.guild.default_role, manage_channels=False, manage_permissions=False, read_messages=False, manage_messages=False)
embed = discord.Embed(
color=0xFFD000
)
embed.set_author(
name=f'{ctx.author._user} ha sbloccato il canale {channel_ability_name}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.set_footer(text=f'Motivo: {arg}')
embed.add_field(
name='Sbloccato da:',
value=f'{ctx.author._user}',
inline=True
)
embed.add_field(
name='Canale:',
value=f'{channel_ability_mention}',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
return
else:
embed.set_author(
name=f'{channel_ability_name} è attualmente sbloccato',
icon_url=f'https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
await ctx.send(embed=embed, delete_after=10.0)
return
@lock.error
async def lock_error(ctx, error):
embed=discord.Embed(
color=0xa61022
)
if isinstance(error, commands.CheckFailure):
embed.set_author(
name="Non ti è permesso bloccare il canale!",
icon_url='https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
await ctx.send(embed=embed, delete_after=10.0)
return
要跟踪锁定的频道,可以创建dict:
然后,您可以将
lock
命令更改为:最后,您可以将
templock
命令更改为(我做了很多重构):您的解锁命令如下所示:
相关问题 更多 >
编程相关推荐