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

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

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

问题

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

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.

import random
import discord
from datetime import timedelta

intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.dm_messages = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f'Logged in as {client.user}')
    
@client.event
async def on_message(message):
      if message.content.startswith('test'):
        embed=discord.Embed(color=0x00000)
        embed.add_field(name="test", value="test", inline=False)
        msg=await message.channel.send("testmsg",embed=embed)
        await msg.add_reaction("🃏")

@client.event
async def on_reaction_add(reaction, user):
    embeds = reaction.message.embeds
    embed = embeds[0]
    if reaction.emoji == "🃏" and not user.bot:
        await user.timeout(until=timedelta(minutes=10),reason="lol")
        await reaction.remove(user)

client.run("token")

the error I get is the following

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

答案1

得分: 1

基本上,不要这样做:

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

而要这样做:

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

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

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

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

希望对你有所帮助。

英文:

Basically instead of this

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

Do this

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:

确定