英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论