【发布时间】:2022-01-16 21:49:21
【问题描述】:
我正在尝试使用 discord.py 创建一个建议系统。用户向机器人发送消息,机器人在特定频道中发送该消息。该代码有效,我想了解是否可以在向机器人发送 DM 时添加冷却时间以及如何做到这一点。
@client.event
async def on_message(message):
if not message.author.bot:
if isinstance(message.channel, DMChannel):
if len(message.content) > 700:
await message.channel.send("Suggerimento troppo lungo")
else:
embedMod= discord.Embed(title="Suggerimento:", description=message.content, colour=0xfc5a50, timestamp=datetime.utcnow())
embedMod.set_footer(icon_url="https://s3.us-west-2.amazonaws.com/cdn.lnk.bio/profilepics/-1230732_20210524863.jpg")
embedMod.set_author(name=f'{message.author}', icon_url=f'{message.author.avatar_url}')
mod = client.get_channel(900085945414582312)
await mod.send(embed=embedMod)
await message.channel.send('Suggerimento registrato con successo, grazie mille.')
更新,对吗?
@client.event # Suggerimenti
async def on_message(message):
bucket = cd_mapping.get_bucket(message)
retry_after = bucket.update_rate_limit()
if retry_after:
await message.channel.send("Scimmia")
else:
if not message.author.bot:
if isinstance(message.channel, DMChannel):
if len(message.content) > 700:
await message.channel.send("Suggerimento troppo lungo")
else:
embedMod= discord.Embed(title="Suggerimento:", description=message.content, colour=0xfc5a50, timestamp=datetime.utcnow())
embedMod.set_footer(icon_url="https://s3.us-west-2.amazonaws.com/cdn.lnk.bio/profilepics/-1230732_20210524863.jpg")
embedMod.set_author(name=f'{message.author}', icon_url=f'{message.author.avatar_url}')
mod = client.get_channel(900085945414582312)
await mod.send(embed=embedMod)
await message.channel.send('Suggerimento registrato con successo, grazie mille.')
else:
await client.process_commands(message)
【问题讨论】:
-
这能回答你的问题吗? cooldown for on_message in discord.py
标签: discord.py