Here is the main bot and a cog all the commands in all of the cogs are running twice whenever called and I know there is only 1 instance of the bot running and there are no duplicate commands. I have even switched text editors and have had multiple people look over my code and they can't figure it out any help is needed thanks.
Main Bot called main_Bot.py
#imports
from cogs.database import database
import discord
import time
import random
from discord.abc import GuildChannel
from discord.embeds import Embed
from discord.ext import commands
import asyncio
import os
import json
import time
import requests
from bs4 import BeautifulSoup
from discord.ext import tasks
os.chdir(os.getcwd())
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="-",intents=intents)
client.remove_command("help")
client.load_extension("cogs.moderation")
client.load_extension("cogs.fun")
client.load_extension("cogs.events")
client.load_extension("cogs.eco")
client.load_extension("cogs.help")
print("loaded")
async def newServer(ctx,guild):
role = discord.utils.get(guild.roles,name = "Muted")
@client.event
async def on_ready():
#when the bot powers on
print("Ready")
print(discord.__version__)
await client.change_presence(status=discord.Status.online, activity=discord.Game('Type -help'))
clearTXT.start()
DailyTimer.start()
muteTime.start()
@tasks.loop(seconds=10)
async def clearTXT():
with open("spam_detect.txt", "r+") as file:
file.truncate(0)
@tasks.loop(seconds=60)
async def DailyTimer():
users = await database.get_bank_data()
for i in users:
user = await client.fetch_user(i)
daily_timer = users[str(user.id)]["daily_timer"]
if daily_timer <= 0:
users[str(user.id)]["daily"] = True
else:
users[str(user.id)]["daily_timer"] -= 10
@tasks.loop(seconds=60)
async def muteTime():
users = await database.get_muted_data()
mod_chat = client.get_channel(778671755115888670)
print("muted Time")
for i in users:
print("Looped")
user = await client.fetch_user(i)
print(user)
daily_timer = users[str(user.id)]["time"]
print(daily_timer)
if daily_timer > 0:
users[str(i)]["time"] -= 60
print("Munis 60")
with open("muted_players.json", "w") as f:
json.dump(users,f,indent=2)
else:
print("unmuted")
getGuild = users[str(user.id)]["server"]
guild = client.get_guild(getGuild)
member = guild.get_member(user.id)
mute_role=discord.utils.get(guild.roles, name="Muted")
await member.remove_roles(mute_role)
# await deleteMuted(user)
with open("muted_players.json", "w") as f:
users.pop(str(user.id))
json.dump(users,f,indent=2)
embed = discord.Embed(description= f"✅ **{member.display_name} mute has run out and is now unmuted**", color=discord.Color.green())
await mod_chat.send(embed=embed)
#run client server
client.run('' )
One of the Cogs called fun.py
import discord
import asyncio
from discord import client
from discord.ext import commands
import requests
from bs4 import BeautifulSoup
import random
class fun(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Fun Cog Loaded")
@commands.command(name="test")
async def test(self,ctx):
await ctx.send("this is a test")
@commands.command(name="embed")
@commands.has_permissions(manage_messages=True)
async def embed(self,ctx,channel:discord.TextChannel,title, * ,words_embed):
person = ctx.author.display_name
words = words_embed
print(words)
em = discord.Embed(title = title, color = discord.Color.dark_red())
em.description = words
# em.add_field(name=person,value=words)
# em.set_footer(text = person)
await channel.send(embed = em)
await ctx.message.delete()
@commands.command(name="message")
@commands.has_permissions(manage_messages=True)
async def embed(self,ctx,channel:discord.TextChannel, * words_embed):
words = ' '.join([str(words) for words in words_embed])
print(words)
await channel.send(words)
await ctx.message.delete()
@commands.command(name='wiki')
async def wikipedia(self,ctx):
a = "https://en.wikipedia.org/wiki/Special:Random"
u = requests.get(a)
soup = BeautifulSoup(u.content, 'html.parser')
title = soup.find(class_ = "firstHeading").text
title = title.replace(" ", "_")
url = 'https://en.wikipedia.org/wiki/%s' %title
await ctx.send(f"""Here is your random Wikipedia article!
{title} - {url}""")
@commands.command(name="flip")
async def flip(self,ctx):
results = random.randrange(0,2)
print(results)
if results == 1:
em = discord.Embed(title = f"The coin landed on Heads!", color = discord.Color.dark_blue())
await ctx.send(embed = em)
elif results == 0:
em = discord.Embed(title = f"The coin landed on Tails!", color = discord.Color.dark_blue())
await ctx.send(embed = em)
def setup(client):
client.add_cog(fun(client))
Ctrl + Shift + Esc
) – Łukasz Kwieciński