我对命令检查以及是否可以绕过命令参数有疑问。
我正在为我的邮件不一致机器人发送回复命令,而不是使用命令reply <user> <message>
我想删除参数user,而只使用reply <message>
。
但是,我需要像使用它作为命令参数一样获得用户。这可能吗?
这是我正在从事的工作:
@commands.command()
@checks.is_channel_mod()
async def reply(self, ctx, user: discord.User, *, message):
"""Send a message thread reply to user."""
if not user.dm_channel:
await user.create_dm()
try:
if ctx.message.channel.name == f"{user.name.lower()}{user.discriminator}":
time = datetime.utcnow()
msg_sent = message[:2000] or "blank"
embed = discord.Embed(title=f"Moderator Reply", description=msg_sent, timestamp=time, colour=discord.Colour(0xff8100))
embed.set_footer(text=f"Sent by {ctx.author.name}#{ctx.author.discriminator}")
msg = await user.dm_channel.send(embed=embed)
await ctx.send(f"{ctx.author.name} sent a reply to {user.name}.")
else:
await ctx.send(f'Please check you have the correct channel or thread ID.')
except discord.Forbidden:
await ctx.send(f"Reply cannot be sent because {user.name}'s direct messages are set to private.")
except discord.HTTPException:
await ctx.send('I failed in sending the message.')
except Exception as e:
await ctx.send(f'There\'s been a problem while sending the message that\'s not of type "Forbidden" or'
f' "HTTPException", but {e}.')
答案 0 :(得分:-1)
我会这样,您可以用任何想要发生的事情代替通行证。
user = ""
@client.event
async def on_message(message):
global user
if "Direct Message" in str(message.channel):
user = message.author
@client.command()
async def reply(ctx, *, message):
global user
if user != "":
pass
return
await ctx.send("No messages recieved")