因此,我创建了这个命令,所有者可以使用该命令向使用机器人的人发送消息以进行审核,因此该部分可以工作并且它会发送消息,但我添加了一个 if 语句,并且它应该仅在具有以下功能的人时才有效我添加的 ids 正在使用它,但它适用于每个人,任何人都可以使用它,我没有收到任何错误,并且我确信 ids 是正确的。 代码如下。
@commands.command()
async def dm(self, ctx, member:discord.Member=None, *, message=None):
m1 = self.client.get_user(775277904481353749)
m2 = self.client.get_user(709295989596356609)
if member == None:
await ctx.send("You have to mention the user that you want to send a message to!")
return
if message == None:
await ctx.send("You have to type the message that you want to send to the mentioned user!")
return
if ctx.message.author == m1 or m2:
await member.send(message)
await ctx.send(f"Successfully sent your message to **{member.name}#{member.discriminator}**")
else:
await ctx.send("You can't use this command!")
return
你不能像这样比较两个变量。你所做的相当于
if (ctx.message.author == m1) or (m2 == True):
并且如果
m2
对应于有效成员,则 709295989596356609
始终为 true,这就是每个人都可以使用它的原因。
你需要做
if ctx.message.author == m1 or ctx.message.author == m2: