Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord bot运行命令两次Discord.py_Python_Python 3.x_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python Discord bot运行命令两次Discord.py

Python Discord bot运行命令两次Discord.py,python,python-3.x,discord.py,discord.py-rewrite,Python,Python 3.x,Discord.py,Discord.py Rewrite,这是主bot和一个cog所有cog中的命令在调用时都运行两次,我知道只有一个bot实例在运行,并且没有重复的命令。我甚至切换了文本编辑器,让多人查看了我的代码,但他们无法确定是否需要任何帮助。谢谢 名为Main_Bot.py的主Bot #导入 从cogs.database导入数据库 进口不和 导入时间 随机输入 从discord.abc导入GuildChannel 从discord.embeds导入嵌入 从discord.ext导入命令 导入异步 导入操作系统 导入json 导入时间 导入请求

这是主bot和一个cog所有cog中的命令在调用时都运行两次,我知道只有一个bot实例在运行,并且没有重复的命令。我甚至切换了文本编辑器,让多人查看了我的代码,但他们无法确定是否需要任何帮助。谢谢

名为Main_Bot.py的主Bot

#导入
从cogs.database导入数据库
进口不和
导入时间
随机输入
从discord.abc导入GuildChannel
从discord.embeds导入嵌入
从discord.ext导入命令
导入异步
导入操作系统
导入json
导入时间
导入请求
从bs4导入BeautifulSoup
从discord.ext导入任务
os.chdir(os.getcwd())
intents=discord.intents.default()
intents.members=True
client=commands.Bot(command_prefix=“-”,intents=intents)
client.remove_命令(“帮助”)
客户端加载扩展(“cogs.moderation”)
客户端加载扩展(“cogs.fun”)
client.load\u扩展(“cogs.events”)
客户端加载扩展(“cogs.eco”)
client.load\u扩展(“cogs.help”)
打印(“已加载”)
异步def新闻服务器(ctx,公会):
role=discord.utils.get(guild.roles,name=“Muted”)
@客户端事件
_ready()上的异步定义:
#当机器人启动时
打印(“就绪”)
打印(不一致的版本)
等待客户。更改状态(状态=discord.status.online,活动=discord.Game('Type-help'))
clearTXT.start()
DailyTimer.start()
muteTime.start()
@tasks.loop(秒=10)
异步def clearTXT():
打开(“spam_detect.txt”、“r+”)作为文件:
文件。截断(0)
@tasks.loop(秒=60)
异步def DailyTimer():
用户=等待数据库。获取银行数据()
对于i-in用户:
user=wait client.fetch\u用户(i)
每日计时器=用户[str(user.id)][“每日计时器”]
如果每日计时器为0:
用户[str(i)][“时间”]-=60
印刷品(“市政60”)
以open(“muted_players.json”、“w”)作为f:
dump(用户,f,缩进=2)
其他:
打印(“取消静音”)
getGuild=users[str(user.id)][“服务器”]
帮会=客户。获取帮会(getGuild)
member=guild.get_成员(user.id)
mute\u role=discord.utils.get(guild.roles,name=“mute”)
等待成员。删除\u角色(静音\u角色)
#等待删除静音(用户)
以open(“muted_players.json”、“w”)作为f:
users.pop(str(user.id))
dump(用户,f,缩进=2)
嵌入=不协调。嵌入(说明=f“✅ **{member.display_name}静音已用完,现在取消静音**”,color=discord.color.green()
等待mod_chat.send(嵌入=嵌入)
#运行客户端服务器
client.run(“”)
其中一个齿轮叫做fun.py

导入不一致
导入异步
从discord导入客户端
从discord.ext导入命令
导入请求
从bs4导入BeautifulSoup
随机输入
课堂乐趣(commands.Cog):
定义初始化(自我,客户机):
self.client=client
@commands.Cog.listener()
异步def on_就绪(自):
打印(“有趣的齿轮加载”)
@commands.command(name=“test”)
异步def测试(自身、ctx):
等待ctx.send(“这是一个测试”)
@commands.command(name=“embed”)
@commands.has_权限(manage_messages=True)
异步def嵌入(self,ctx,channel:discord.TextChannel,title,*,words\u嵌入):
person=ctx.author.display\u name
单词=单词
印刷品(字)
em=discord.Embed(title=title,color=discord.color.dark_red())
em.description=单词
#em.add_字段(姓名=人,值=单词)
#em.set_页脚(文本=人)
等待通道发送(嵌入=em)
等待ctx.message.delete()
@commands.command(name=“message”)
@commands.has_权限(manage_messages=True)
异步定义嵌入(self、ctx、channel:discord.TextChannel、*words\u嵌入):
words=''.join([str(words)表示words\u嵌入中的单词])
印刷品(字)
等待频道。发送(文字)
等待ctx.message.delete()
@commands.command(name='wiki')
异步定义维基百科(self,ctx):
a=”https://en.wikipedia.org/wiki/Special:Random"
u=请求。获取(a)
soup=BeautifulSoup(u.content'html.parser')
title=soup.find(class=“firstHeading”).text
标题=标题。替换(“,”)
url='1〕https://en.wikipedia.org/wiki/%s“%title”
等待ctx.send(f“”)这是你的随机维基百科文章!
{title}-{url}'')
@commands.command(name=“flip”)
异步def翻转(自身、ctx):
结果=随机。随机范围(0,2)
打印(结果)
如果结果==1:
em=discord.Embed(title=f“硬币落在头上!”,color=discord.color.深蓝()
等待ctx.send(嵌入=em)
elif结果==0:
em=discord.Embed(title=f“硬币落在尾巴上!”,color=discord.color.深蓝()
等待ctx.send(嵌入=em)
def设置(客户端):
客户。添加_cog(乐趣(客户))
提供了以下解决方案:

如果有

@commands.Cog.listener()
async def on_message(..):
在您加载的任何其他齿轮扩展中运行, 拆下线路

await self.client.process_commands(message)

从它的身体。cogs加载的扩展文件中不需要它,只需要在主文件中使用。

您确定没有运行任何隐藏的python进程吗?要选中打开任务管理器(
Ctrl+Shift+Esc
)是的,我确定我在任务管理器运行一次之前选中了它,没有隐藏。您是否使用IDE运行python文件?像vscode或pycharm?是的,我正在使用VS代码。请尝试关闭它,并关闭任务管理器中的所有实例,如果它不起作用,请尝试重新启动电脑