Discord 机器人不要踢自己或机器人
Discord bot dont kick yourself or the bot
我有以下命令:
@bot.command()
@commands.is_owner()
async def kick(ctx, member:discord.Member = None, *, reason="You smell bozo."):
if(member == None):
await ctx.reply("*Check your arguments!*\n```/kick @MEMBER REASON(optional)```")
else:
await member.kick(reason=reason)
@bot.command()
@commands.is_owner()
async def ban(ctx, member:discord.Member = None, *, reason="Bye Bye! :D."):
if(member == None):
await ctx.reply("*Check your arguments!*\n```/kick @MEMBER REASON(optional)```")
else:
await member.ban(reason=reason)
但是我怎样才能得到它,这样我就不会不小心踢到自己或机器人本身了?
我需要像 member=my_id 那样做吗?完全不熟悉制作不和谐的机器人,希望有人能提供帮助。
考虑添加这样的检查并在返回之前添加类似消息的内容:
if ctx.author.id in (member.id, self.bot.user.id):
await return ctx.send("<message>")
此外,您应该考虑将禁令从 discord.Member
更改为 discord.User
,因为 Member
仅限于仍在公会中的人,并将其与支票配对如果他们不在公会中,这将获取用户:
if not isinstance(user, discord.Member):
user = await self.bot.fetch_user(user)
我有以下命令:
@bot.command()
@commands.is_owner()
async def kick(ctx, member:discord.Member = None, *, reason="You smell bozo."):
if(member == None):
await ctx.reply("*Check your arguments!*\n```/kick @MEMBER REASON(optional)```")
else:
await member.kick(reason=reason)
@bot.command()
@commands.is_owner()
async def ban(ctx, member:discord.Member = None, *, reason="Bye Bye! :D."):
if(member == None):
await ctx.reply("*Check your arguments!*\n```/kick @MEMBER REASON(optional)```")
else:
await member.ban(reason=reason)
但是我怎样才能得到它,这样我就不会不小心踢到自己或机器人本身了? 我需要像 member=my_id 那样做吗?完全不熟悉制作不和谐的机器人,希望有人能提供帮助。
考虑添加这样的检查并在返回之前添加类似消息的内容:
if ctx.author.id in (member.id, self.bot.user.id):
await return ctx.send("<message>")
此外,您应该考虑将禁令从 discord.Member
更改为 discord.User
,因为 Member
仅限于仍在公会中的人,并将其与支票配对如果他们不在公会中,这将获取用户:
if not isinstance(user, discord.Member):
user = await self.bot.fetch_user(user)