python-3.x - Discord.py 重复消息
问题描述
我用 cogs 在 discord py 上写 bot。
主要的:
intents = discord.Intents.all()
client = discord.Bot(command_prefix = '$', intents = intents)
for files in os.listdir('./cogs'):
if files.endswith('.py'):
client.load_extension(f'cogs.{files[:-3]}')
token = os.environ.get('token')
client.run(token, bot=True)
和齿轮:
class textCommands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def ping(self, ctx):
await ctx.send(f'Pong! {round(self.client.latency * 1000)}ms')
def setup(client):
client.add_cog(textCommands(client))
如果我发送“ping”,我的机器人会发送两条消息,我更改了我的令牌,但问题仍然存在。
解决方案
所以,我找到了答案。我await self.client.process_commands(message)
从我的代码中删除并且两次消息丢失
推荐阅读
- python-3.x - 另一个 Setup.py 错误:无法识别选项 -f
- junit - Mockito:如何测试更改私有字段值的方法?
- python - 使用 `send_keys(Keys.CONTROL + 't')` 打开一个新选项卡不起作用并且不显示任何错误
- amazon-web-services - 允许具有公共主机名的源安全组 ALB 访问
- java - 使用 OpenJDK 1.8 的 JavaFX 的 Maven 依赖项
- oracle - 如何在批量收集循环中进行条件处理?
- javascript - 有没有一种方法可以检查数组中是否有任何值?
- azure - 无法恢复 NuGet 包:“找不到区域的 api 位置:nuget id:9D3A4E8E”
- javascript - 将生成的 0 移动到数组的开头
- python - 抓取内容中的标签必须与原始 HTML 文件中的标签具有相同的顺序