【发布时间】:2021-04-04 03:49:19
【问题描述】:
我的 Discord Bot 似乎每件事都做了两次。起初,我认为这是一个 cog 问题,但在向主 .py 文件添加测试功能后,即使执行 #test 也会响应两次。此外,当运行无法识别的命令时,我会收到两次错误消息。我该如何修改?
import discord
from discord.ext import commands, tasks
import os #For Loading/Unloading Cogs
token="[redacted]"
help_command = commands.DefaultHelpCommand(no_category = "Placeholder")
client=commands.Bot(command_prefix="#", help_command=help_command) #The prefix for the Bot is "#", Changes the default group title for cogless commands.
for filename in os.listdir("./cogs"):
if filename.endswith(".py"): #Checks that the file in the cogs folder ends with ".py".
client.load_extension(f"cogs.{filename[:-3]}") #Loads cogs whilst cutting of the ".py" file extenstion.
print(f"{filename} has been loaded")
@client.command()
async def test(ctx):
await ctx.send("test done")
client.run(token)
【问题讨论】:
-
运行任务管理器(
Ctrl + Shift + Esc)并搜索隐藏的python进程并杀死它们,另一种选择是重新启动电脑
标签: python discord discord.py