I'm working on a discord bot and everything was working correctly but suddenly I got this error and I just can't figure out what should i do.
Could not prepare the client: Traceback (most recent call last): File "C:\Users\Barni\AppData\Local\Programs\Python\Python310\lib\site-packages\interactions\client\bot.py", line 444, in _ready self._intents.GUILD_PRESENCES in self._intents AttributeError: 'Intents' object has no attribute 'GUILD_PRESENCES'
here is my code:
import discord
from discord.ext import commands,tasks
import random
import interactions
import asyncio
intents = discord.Intents.default()
intents.presences = True
intents.members = True
bot = interactions.Client(token="**token**", intents=intents)
#bot.event
async def on_member_join(member):
guild = bot.get_guild(**my servers id**)
welcome_channel = guild.get_channel(**welcome channels id**)
embed = discord.Embed(title="Üdv a szerveren!", colour=discord.Colour(0x2ecc71),description=f'{member.mention}')
await channel.send(embed=embed)
suntzulist=[]
file=open("suntzu.txt","r")
for sor in file:
suntzulist.append(sor.strip())
file.close()
#bot.command(name="suntzu", description="Random Sun Tzu idézet", scope=879081332590927892)
async def suntzu(ctx: interactions.CommandContext):
await ctx.send(random.choice(suntzulist))
#bot.command(name="help", description="parancsok megmutatása", scope=879081332590927892)
async def help(ctx: interactions.CommandContext):
await ctx.send("`help` `suntzu`")
#bot.event
async def on_ready():
print('-------------')
print('Bejelentkezve')
print('-------------')
bot.start()
I tried reinstalling the interactions plugin I but got the same error.
I also tried intents.guild_presences = True but then I got this
Traceback (most recent call last): File "C:\Users\Barni\Desktop\PratBOT.py", line 10, in <module> intents.guild_presences = True AttributeError: 'Intents' object has no attribute 'guild_presences'
Related
trying to make a global banning system with cogs but it gives me cog errors and im not too good with cog. the code is from an old github repo by the way so i dont take credit for this.
bot.py:
import discord
import os
import json
from discord.ext import commands
client = commands.Bot(command_prefix = ".")
client.remove_command("help")
#client.event
async def on_ready():
print("Global Banning System is online!")
for filename in os.listdir("cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.gbs")
client.run(token)
and i also have another file in a new folder ("cogs") that is called "gbs.py".
gbs.py:
import discord
from discord.ext import commands
class gbs(commands.Cog):
def __init__(self, client):
self.client = client
#commands.command()
#commands.has_role(roleid) # Staff's Role
async def gban(self, ctx, member: discord.User):
channel = self.client.get_channel(channelid) # Logs
auth = ctx.author
await ctx.send("Ban Issue successfuly opened. Now, please type the ban reason!")
reason = await self.client.wait_for('message', timeout = 600)
embed = discord.Embed(title = f"Global Banned {member.name}", colour = 0xFF0000)
embed.add_field(name = "Reason:", value = reason.content, inline = False)
embed.add_field(name = "User ID:", value = f"`{member.id}`",)
embed.add_field(name = "Staff Member:", value = f"{auth.name}")
embed.set_thumbnail(url = member.avatar_url)
await ctx.send(embed = embed)
await ctx.send(f"**{member.name}** has been globbaly banned!")
for guild in self.gbs.guilds:
await guild.ban(member)
def setup(client):
gbs.add_cog(gbs(client))
This is the errors that it gives me.
Traceback (most recent call last):
File "C:\Users\user-01\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 723, in _load_from_module_spec
setup(self)
File "C:\Users\user-01\Desktop\Global Banning System - Discord Bot\cogs\gbs.py", line 28, in setup
gbs.add_cog(gbs(client))
AttributeError: type object 'gbs' has no attribute 'add_cog'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\user-01\Desktop\Global Banning System - Discord Bot\bot.py", line 15, in <module>
client.load_extension(f"cogs.gbs")
File "C:\Users\user-01\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 783, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\user-01\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 728, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'cogs.gbs' raised an error: AttributeError: type object 'gbs' has no attribute 'add_cog'
You add a cog class to your bot not to your gbs. So replace gbs with client to solve the problem.
def setup(client):
# instead of gbs.add_cog...
client.add_cog(gbs(client)
Documentation
I made this script for my discord bot:
import discord
from discord.ext import commands
from keep_alive import keep_alive
bot = commands.Bot(command_prefix = '+')
bot.remove_command('help')
#bot.event()
async def on_ready():
await bot.change_presence(activity = discord.Streaming(name = "", url=""))
keep_alive()
bot.run('it is my token >:(')
and i got this error:
Traceback (most recent call last):
File "main.py", line 8, in <module>
#bot.event()
TypeError: event() missing 1 required positional argument: 'coro'
Then how can i fix this?
I'm guessing the problem is with your decorator.
I believe it should be just:
#bot.event
async def on_ready():
await bot.change_presence(activity = discord.Streaming(name = "", url=""))
There is this "Traceback (most recent call last):
File "main.py", line 11, in
#client.command()
AttributeError: 'Client' object has no attribute 'command'" error coming is there something i did wrong in the code?
import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.ext.commands import has_permissions, MissingPermissions, is_owner
import json
client = discord.Client(command_prefix = ".")
status=discord.Status.idle
#client.command()
async def ban(ctx, member: discord.Member, reason=None):
await member.ban(reason=reason)
await ctx.send("member is banned")
#client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))
my_secret = os.environ['Token']
client.run(my_secret)
change client = discord.Client(command_prefix = ".")
to
client = commands.Bot(command_prefix='.')
# You have to write
# client = commands.Bot(command_prefix = '!')
# then you only write client.command() in line (11)
# And you have to also import from discord.ext import commands in line 2
import discord
from discord.ext import commands
import os
client = commands.Bot(command_prefix = '!')
#client.event
async def on_ready():
print("Bot is Online")
#client.command()
async def ping(ctx):
await ctx.send("Pong")
client.run('WRITE YOUR TOKEN HERE')
I wrote this code:
import discord
import os
async def on_ready():
await client.change_presence(game=discord.Game(name=" dm for support ;)"))
client.run("<TOKEN>")
TOKEN = os.environ['TOKEN']
but I keep getting this error
Traceback (most recent call last):
File "main.py", line 10, in
client.run("")
NameError: name 'client' is not defined
You haven't created the client object you're using, you can create one by doing this before using the client object in your code:
client = discord.Client()
I am new to programming and just started learning it, I was trying to code a discord bot just for fun but I'm having some errors and I can't seem to figure out what the reason is. The error I'm getting:
Traceback (most recent call last):
File "Directory", line 7, in <module>
async def on_message(message):
TypeError: event() missing 1 required positional argument: 'coro'
Here's my code:
import discord
client = discord.Client
keywords = ["Keywords for Messages"]
#client.event
async def on_message(message):
for i in range(len(keywords)):
if keywords[i] in message.content:
await message.channel.send("Reply Message")
client.run(Secret.Token)
You forgot the parenthesis in your client constructor:
client = discord.Client()