Discord.py(rewrite)mute命令始终返回相同的响应

2024-09-21 05:21:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试构建一个discord.py mute命令,该命令发送一个嵌入,询问用户是否确实想要静音,然后在添加反应时执行静音并编辑嵌入。我在尝试这样做时遇到了一些错误

@bot.command()
@commands.has_permissions(manage_guild=True)
async def mute(ctx, message, member: discord.Member = None):
  
  guild = ctx.guild
  user = member

  if member == None:
    await ctx.send(f'**{ctx.message.author},** please mention somebody to mute.')
    return 

  if member == ctx.message.author:
    await ctx.send(f'**{ctx.message.author},** you cannot mute yourself, silly.')
    return 
  
  for role in guild.roles:
    if role.name == "Muted":
      if role in user.roles:
                await ctx.send("**{}** is already muted.".format(user))
                return

  embedcheck=discord.Embed(title="Mute", colour=0xFFD166, description=f'Are you sure you want to mute **{user}?**')
  
  embeddone=discord.Embed(title="Muted", colour=0x06D6A0,description=f'The mute has been done. **{user}** cannot talk in any channels anymore.')

  embedfail=discord.Embed(title="Not Muted",colour=0xEF476F,description=f'The mute did not carry out as I did not receive a reaction in time.')

  msg = await ctx.send(embed=embedcheck)
  await message.add_reaction('✅','❌')

  try:
      def check(rctn, user):
        return user.id == ctx.author.id and str(rctn) == '✅'
      reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
  except asyncio.TimeoutError:
      await msg.edit(embed=embedfail)
  else:
      for role in guild.roles:
        if role.name == "Muted":
            await member.add_roles(role)
            await msg.edit(embed=embeddone)

当我运行命令时,我总是得到相同的输出,“……请提及要静音的人”,即使我提到过某人。当我没有提到任何人时,我就犯了错误

    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: message is a required argument that is missing.

Tags: insendmessagereturnifawaitroleauthor
1条回答
网友
1楼 · 发布于 2024-09-21 05:21:55

在{}中省略{},并将{}更改为{}

@bot.command()
@commands.has_permissions(manage_guild=True)
async def mute(ctx, member: discord.Member = None):
  
  guild = ctx.guild
  user = member

  if member == None:
    await ctx.send(f'**{ctx.message.author},** please mention somebody to mute.')
    return 

  if member == ctx.message.author:
    await ctx.send(f'**{ctx.message.author},** you cannot mute yourself, silly.')
    return 
  
  for role in guild.roles:
    if role.name == "Muted":
      if role in user.roles:
                await ctx.send("**{}** is already muted.".format(user))
                return

  embedcheck=discord.Embed(title="Mute", colour=0xFFD166, description=f'Are you sure you want to mute **{user}?**')
  
  embeddone=discord.Embed(title="Muted", colour=0x06D6A0,description=f'The mute has been done. **{user}** cannot talk in any channels anymore.')

  embedfail=discord.Embed(title="Not Muted",colour=0xEF476F,description=f'The mute did not carry out as I did not receive a reaction in time.')

  msg = await ctx.send(embed=embedcheck)
  await msg.add_reaction('✅')
  await msg.add_reaction('❌')

  try:
      def check(rctn, user):
        return user.id == ctx.author.id and str(rctn) == '✅'
      reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
  except asyncio.TimeoutError:
      await msg.edit(embed=embedfail)
  else:
      for role in guild.roles:
        if role.name == "Muted":
            await member.add_roles(role)
            await msg.edit(embed=embeddone)

您提到一个用户转到了message,而不是member。不提及任何人会使message为空并向您发送一个错误,因为它是必需的参数

我没有检查它是否将静音,但这将修复您丢失的RequiredArgument错误

相关问题 更多 >

    热门问题