关于命令检查和命令参数使用问题的问题
Question about command checks and command argument use issue
我对命令检查以及是否可以绕过命令参数有疑问。
我正在为我的邮件 discord 机器人发出回复命令,而不是使用命令 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}.')
我会这样做,你可以用你想要发生的任何事情来代替pass。
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")
我对命令检查以及是否可以绕过命令参数有疑问。
我正在为我的邮件 discord 机器人发出回复命令,而不是使用命令 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}.')
我会这样做,你可以用你想要发生的任何事情来代替pass。
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")