gpt4 book ai didi

Discord.py新超时命令错误: "AttributeError: ' User' object has no attribute 'timeout_for' "

转载 作者:行者123 更新时间:2023-12-02 18:23:08 26 4
gpt4 key购买 nike

大家好,2022 年新年快乐!!

自从最近为不和谐添加了“超时”以来,我尝试按照一些教程制作超时命令,例如:

https://docs.pycord.dev/en/master/api.html?highlight=timeout#discord.Member.timeout

https://youtu.be/c5V4OaTNDtM

但由于我不知道的原因,我可能会收到以下错误:

Ignoring exception in command timeout2:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/Russia-Bot/moderator.py", line 42, in timeout2
await member.timeout_for(time)
AttributeError: 'Member' object has no attribute 'timeout_for'

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Member' object has no attribute 'timeout_for'

这是命令代码,我做了两个不同的命令,但都给出了相同的问题:

变体 1:

@client.command()
async def timeout(ctx, member: discord.Member, time=None, reason=None):
time = humanfriendly.parse_timespan(time)
await member.timeout(until = discord.utils.utcnow() + datetime.timedelta(seconds=time), reason=reason)
await ctx.send (f"{member} callate un rato anda {time}")

变体 2

@client.command(pass_context =True)
async def timeout2(ctx, member:discord.User=None, time=None):
#time = humanfriendly.parse_timespan(time)
# tiempo = datetime.timedelta(seconds=time)
user = await client.fetch_user(member)
#await ctx.send (f"{user}")
#await ctx.send (f"{member}")

await user.timeout_for(time)
await ctx.send (f"{user} callate un rato anda {time}")

最诚挚的问候,工程师

最佳答案

使用pip install -U git+https://github.com/pycord-development/pycord更新您的py-cord库

如果有效,请考虑接受答案

关于Discord.py新超时命令错误: "AttributeError: ' User' object has no attribute 'timeout_for' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70592409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com