'AttributeError: 'function' object has no attribute 'add_signal_handler'
So I tried to run my discord bot but I get this error loop.add_signal_handler(signal.SIGINT, lambda: loop.stop()) AttributeError: 'function' object has no attribute 'add_signal_handler', I reinstalled python 3.10.3 and discord.py 1.7.3, I checked my code for syntax errors and none to be found and the error still comes up. Any help?
Traceback (most recent call last):
File "C:\Users\myname\OneDrive\Documents\discordbot\main.py", line 63, in <module>
client.run("MASKED")
File "C:\Users\myname\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 695, in run
loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
AttributeError: 'function' object has no attribute 'add_signal_handler'
Heres my code:
import discord
from discord.ext import commands
from pymongo import MongoClient
import time
import json
mongo_url = "MASKED"
cluster = MongoClient(mongo_url)
db = cluster["MASKED"]
collection = db["MASKED"]
f = open('images.json')
data = json.load(f)
g = data['images']['g']
r = data['images']['g']
client = commands.Bot(command_prefix='f')
client.remove_command('help')
yellow = 0xffde48
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name='fstart'))
print('ready')
@client.event
async def loop(ctx):
await ctx.channel.send("f")
@client.command()
async def start(ctx):
author_id = ctx.author.id #author id
guild_id = ctx.guild.id #guild id
initial_embed = discord.Embed(color=0x2F3136,
description=f'stuff')
initial_embed.set_image(url=starter_box)
if (collection.count_documents({})==0):
user_info={'id':author_id,
'player_name':ctx.author.name,
'guild_id':guild_id,
'level':0}
collection.insert_one(user_info)
await ctx.channel.send(
ctx.author.mention,
embed=initial_embed,
)
@client.command()
async def help(ctx):
help_embed = discord.Embed(color=yellow,
description='')
@client.command()
async def myprofile(ctx):
profile_embed = discord.Embed(color=yellow, description=f"***{ctx.author.name}'s Profile***")
await ctx.channel.send(embed=profile_embed)
client.run('MASKED')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|