【发布时间】:2021-12-14 21:46:17
【问题描述】:
我有一个命令允许我编辑文本频道信息,例如名称、主题等。
运行命令时,我每次都会运行相同的命令:.channel > React with E, React with N, type name 我会重复此操作两到三次,通常在第三次尝试时,它会等待 10 分钟,然后才能真正更改名称并编辑嵌入,我问了一个朋友,我们俩都不知道在这种情况下该怎么办。
我也不知道定义 'editstart' 函数以便我可以使用 'back' 是不是最好的做事方式,但这是我遇到困境时首先想到的事情之一。
代码:(我删除了很多,但保留了所有重要的部分)
@commands.command()
@commands.has_permissions(manage_channels=True)
async def channel(self, ctx):
embed=discord.Embed(colour=author.colour)
...
message=await ctx.send(embed=embed)
try:
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in emojis
reaction, user=await self.client.wait_for('reaction_add', timeout=15, check=check)
if str(reaction.emoji) == '????':
information=discord.Embed(colour=author.colour)
...
reactions=[...]
async def addreact():
for reaction in reactions:
await message.add_reaction(f'{reaction}')
await addreact()
async def editstart():
try:
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in reactions
reaction, user=await self.client.wait_for('reaction_add', timeout=30, check=check)
if str(reaction.emoji) == '????':
...
try:
def check(name):
return name.author == ctx.author and name.channel == ctx.channel
name=await self.client.wait_for('message', timeout=30, check=check)
if name.content.lower() == 'back':
await name.delete()
await message.edit(embed=information)
await addreact()
await editstart()
elif name.content.lower() == 'cancel':
embed=discord.Embed(colour=author.colour)
...
await name.delete()
await message.edit(embed=embed)
else:
embed=discord.Embed(colour=author.colour)
...
await channel.edit(name=f"{name.content}")
await name.delete()
await message.edit(embed=embed)
except asyncio.TimeoutError:
await ctx.send(embed=timeouterror, delete_after=3)
elif str(reaction.emoji) == ...:
...
...
except asyncio.TimeoutError:
...
await editstart()
except asyncio.TimeoutError:
...
【问题讨论】:
-
更改频道名称的速率限制为每个频道每10分钟2次
标签: python python-3.x discord discord.py