Bot在尝试通过消息反应超时用户时出现TypeError(discord.py)。

huangapple go评论110阅读模式
英文:

Bot gives TypeError when trying to timeout user via message reaction (discord.py)

问题

抱歉,这是代码错误的问题。要解决这个错误,你可以将timeout方法的调用更改为以下方式,将until参数作为位置参数传递:

  1. await user.timeout(timedelta(minutes=10), reason="lol")

这应该可以解决你的问题。

英文:

I have been building a discord bot for some time. Currently tring to timeout users if they react with the wrong emoji. My discord bot gives me an error when i try to timeout user via reaction.

  1. import random
  2. import discord
  3. from datetime import timedelta
  4. intents = discord.Intents.default()
  5. intents.message_content = True
  6. intents.members = True
  7. intents.dm_messages = True
  8. client = discord.Client(intents=intents)
  9. @client.event
  10. async def on_ready():
  11. print(f'Logged in as {client.user}')
  12. @client.event
  13. async def on_message(message):
  14. if message.content.startswith('test'):
  15. embed=discord.Embed(color=0x00000)
  16. embed.add_field(name="test", value="test", inline=False)
  17. msg=await message.channel.send("testmsg",embed=embed)
  18. await msg.add_reaction("🃏")
  19. @client.event
  20. async def on_reaction_add(reaction, user):
  21. embeds = reaction.message.embeds
  22. embed = embeds[0]
  23. if reaction.emoji == "🃏" and not user.bot:
  24. await user.timeout(until=timedelta(minutes=10),reason="lol")
  25. await reaction.remove(user)
  26. client.run("token")

the error I get is the following

  1. TypeError: Member.timeout() got some positional-only arguments passed as keyword arguments: 'until'

答案1

得分: 1

基本上,不要这样做:

  1. await user.timeout(until=timedelta(minutes=10),reason="lol")

而要这样做:

  1. await user.timeout(timedelta(minutes=10),reason="lol")

"Positional-only arguments" 意味着你只把你的值作为参数传递,而不是将值作为关键字参数传递。

可以在这里找到一些深入阅读的信息。

这里可以找到关于这个主题的视频。

希望对你有所帮助。

英文:

Basically instead of this

  1. await user.timeout(until=timedelta(minutes=10),reason="lol")

Do this

  1. await user.timeout(timedelta(minutes=10),reason="lol")

Positional-only arguments mean that you only pass your value as an argument not keyword with a value as an argument.

See here for some dense reading.

See here for a video on the subject.

Hope that helps.

huangapple
  • 本文由 发表于 2023年2月8日 21:52:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定