AttributeError: 'CheckingClient' object has no attribute 'logout' - python-3.x

I wanted to turn the discord, but it gives an error.
I found a bot on the Internet, I wanted to take it as a basis, and add various functions in the future. But I downloaded everything, inserted the token and made the first launch and an error.
link to code - https://github.com/sergree/DolboNet
the error itself -
ERROR discord.client Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\alexe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "C:\Users\alexe\Desktop\DolboNet-master\core\checking_client.py", line 13, in on_ready
await self.logout()
AttributeError: 'CheckingClient' object has no attribute 'logout'
import discord
from core.checking_client import CheckingClient
import config
from utils.tprint import log
import asyncio
log("Проверяю Discord токен...")
checking_client = CheckingClient(intents=discord.Intents.none())
login_successful = False
try:
checking_client.run(config.token)
login_successful = True
except discord.errors.LoginFailure:
log("НЕВЕРНЫЙ DISCORD ТОКЕН! Необходимо отредактировать файл config.py!")
if login_successful:
log("Discord токен проверен.")
asyncio.set_event_loop(asyncio.new_event_loop())
from core.main_client import MainClient
intents = discord.Intents.none()
intents.guilds = True
intents.guild_messages = True
intents.emojis = True
main_client = MainClient(intents=intents)
main_client.run(config.token)
Thanks for the help!

Related

How to edit embed with message id discord bot py in on_ready event

I want to edit a embed in on_ready event this is the only way i can edit can do on_message or is there a way to keep a function running until the program ends?
from discord.ext import commands
import discord
from discord.utils import get
#bot.event
async def on_ready():
msg = bot.get_message(892788147287654471)
em = discord.Embed(title="lik",description="kjk")
await msg.edit(embed=em)
bot.run(os.environ['token'])
error code:
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 56, in on_ready
msg = bot.get_message(892788147287654471)
AttributeError: 'Bot' object has no attribute 'get_message'
Well as the error says, bot has no get_message attribute. Instead what you can do is get the channel, and then get the message or partial message within.
https://discordpy.readthedocs.io/en/master/api.html?highlight=partial%20message#discord.PartialMessage
Example:
message = bot.get_channel(1234567890).get_partial_message(1234567890)
await message.edit(content="test")

Facing error when using buttons from discord components in cogs Discord.py

import discord
from discord.ext import commands
bot = discord.ext.commands.Bot(command_prefix = ";");
import random
from asyncio import TimeoutError
import subprocess
import sys
from discord_components import *
class GameCommands(commands.Cog):
def __init__(self, bot):
self.bot=bot
#commands.Cog.listener()
async def on_ready(self):
DiscordComponents(bot)
print('ready')
#commands.command()
async def rps(self,ctx):
choices=['rock','paper','scissors']
bot_choise=random.choice(choices)
player_choise=""
yet= discord.Embed(title=f"{ctx.author.display_name}'s Rock Paper Scissors Game", description="Click On A Button", color=discord.Color.from_rgb(0, 208, 255))
won= discord.Embed(title=f"You Won! Le Hurray!", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(255, 213, 0))
lost= discord.Embed(title=f"You Lost! Sadge :(", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(102, 61, 69))
tie= discord.Embed(title=f"Hmm, A tie!", description=f"You and the bot both chose {bot_choise}", color=discord.Color.from_rgb(137, 49, 181))
out= discord.Embed(title=f"Timeout ", description=f"You didn't choose any option in time, Bruh!", color=discord.Color.from_rgb(43, 194, 146))
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
def check(res):
return ctx.author==res.user and res.channel==ctx.channel
try:
res= await self.bot.wait_for("button_click", check=check, timeout=15)
player_choise= res.component.label
if player_choise==bot_choise:
await m.edit(embed=tie, components=[])
if player_choise=="Paper" and bot_choise=="Rock":
await m.edit(embed=won, components=[])
if player_choise=="Scissors" and bot_choise=="Paper":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Scissors":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Paper":
await m.edit(embed=lost, components=[])
if player_choise=="Paper" and bot_choise=="Scissor":
await m.edit(embed=lost, components=[])
if player_choise=="Scissor" and bot_choise=="Rock":
await m.edit(embed=lost, components=[])
except TimeoutError:
await m.edit(embed=out, components=[])
def setup(bot):
bot.add_cog(GameCommands(bot))
I have discord-components installed, whenever i run the command i get this error:
Ignoring exception in command rps:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/TheDuck/commands/games.py", line 37, in rps
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 46, in send_component_msg_prop
return await self.send_component_msg(ctxorchannel.channel, *args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 177, in send_component_msg
data = await self.bot.http.request(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
AttributeError: 'NoneType' object has no attribute 'request'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'request'
I don't know what is causing this error. I tried finding about it online but couldn't.
I would Like to know what possible mistake i might be making or is it a bug.
I saw almost the same code being run on the main file without any problems. Is it a problem with cogs or my code is wrong?
While I am unsure if that is a bug or not, I think it would be better to use Discord.py 2.0 (Currently in Alpha) for buttons instead of third party libs. Keep in mind it might be unstable so is your choice.

Message in a specific Discord channel

Hi guys i'm trying to make the bot send a message automatically in a specific channel. I took the channel ID and pass it in the if condition (a_string.find ('data: []')! = -1). However this code gives me this error. See OUTPU ERROR.
P.S. I'm using Replit and Live is the file name (Live.py)
from discord.ext import commands
from Naked.toolshed.shell import execute_js, muterun_js
import sys
class Live(commands.Cog):
def __init__(self,client):
self.client=client
#commands.Cog.listener()
async def on_ready(self):
channel = self.get_channel(828711580434169858)
response = muterun_js('serverJs.js')
original_stdout = sys.stdout # Save a reference to the original standard output
if response.exitcode == 0:
a_string= str(response.stdout)#stampa in console
if (a_string.find('data: []') != -1):
print("Streamer: Offline ")
else:
print("Streamer: Online")
await channel.send('Live Link: https://...link....')
else:
sys.stderr.write(response.stderr)
#commands.command()
async def Live(self,ctx):
await ctx.send('')
def setup(client):
client.add_cog(Live(client))
OUTPUT ERROR:
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "/home/runner/Solaris-IA/cogs/Live.py", line 12, in on_ready
channel = self.get_channel(828711580434169858)
AttributeError: 'Live' object has no attribute 'get_channel'
It's self.client.get_channel, not self.get_channel, you haven't defined that function
channel = self.client.get_channel(828711580434169858)

discord.py temporary voices

I am making my bot for discord, I want to do this, when a user clicks on a certain voice channel, a new voice channel is created for him, which is deleted upon exit. Here is the code:
import discord
from discord.ext import commands
from discord.utils import get
import asyncio
TOKEN = 'xxxx'
bot = commands.Bot(command_prefix='!')
#bot.event
async def on_voice_state_update(member, before, after):
if after.channel != None:
if after.channel.id == 700246237244555338:
for guild in bot.guilds:
maincategory = discord.utils.get(
guild.categories, id=700246237244555336)
channel2 = guild.create_voice_channel(name=f'канал {member.display_name}', category=maincategory)
await channel2.set_permissions(member, connect=True, mute_members=True, manage_channels=True)
await member.move_to(channel2)
def check(x, y, z):
return len(channel2.members) == 0
await bot.wait_for('voice_state_update', check=check)
await channel2.delete()
# RUN
bot.run(TOKEN)
But i have error...
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:\Users\asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "jett.py", line 190, in on_voice_state_update
await member.move_to(channel2)
File "C:\Users\asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\member.py", line 626, in move_to
await self.edit(voice_channel=channel, reason=reason)
File "C:\Users\asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\member.py", line 592, in edit
payload['channel_id'] = vc and vc.id
AttributeError: 'coroutine' object has no attribute 'id'
C:\Users\asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py:340: RuntimeWarning: coroutine 'Guild.create_voice_channel' was never awaited
pass
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Can you help me with this problem or just send me working code for temporary voices
RuntimeWarning: Enable tracemalloc to get the object allocation traceback usually means that you forgot to add an await keyword to an async function. The async function in question is likely create_voice_channel, as the documentation says it is an async function.
To fix this, you'll want to add the await keyword before the function call, similar to this:
channel2 = await guild.create_voice_channel(name=f'канал {member.display_name}', category=maincategory)

Flask-SQLAlchemy ERROR: 'No application found. Either work inside a view function or push'

I am in the process of trying to use flask-sqlalchemy, and I have followed numerous examples in the documentation of how to get the Flask application setup. However, I am not able to get the app context for some reason. I am currently using the app.app_context().push() method. Is there some other way to get this to work? What am I doing wrong? Any help would be appreciated.
Currently running:
Python==3.6.3
Flask==0.12.2
Flask-Compress==1.4.0
Flask-SQLAlchemy==2.3.2
model.py
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import relationship
db = SQLAlchemy()
class Property(db.Model):
__tablename__ = 'vt_property'
id = db.Column(db.BigInteger, primary_key=True)
name = db.Column(db.String(32))
value = db.Column(db.LargeBinary)
client_tag = db.Column(db.String(16))
index.py
from flask import Flask, jsonify, request
from flask_compress import Compress
from database.model import *
from manager.some_util import some_user, some_url, some_pass
# App config.
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
Compress(app)
app.secret_key = secret_key
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://connection_string'
db.init_app(app)
app.app_context().push()
some_util.py
from database.model import Property
from helpers.util import secret_key
def load_some_config():
from secure.secure import read_encrypted_text
some_configs = Property.query.filter(Property.name.contains('MANAGER')).all()
some_url = ''
some_user = ''
some_pass = ''
for c in some_configs:
if 'URL' in c.name:
some_url = c.value.decode('utf-8')
if 'USER' in c.name:
some_user = c.value.decode('utf-8')
if 'PASS' in c.name:
some_pass = read_encrypted_text(c.value).decode('utf-8')
return some_url, some_user, some_pass
When I try to run my API, I get this error:
*/venv/bin/python */src/api/index.py
Traceback (most recent call last):
File "*/venv/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 988, in __call__
return self.registry[key]
KeyError: <greenlet.greenlet object at 0xXXXXXXXX>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "*/src/api/index.py", line 16, in <module>
from manager.some_util import some_user, some_url, some_pass
File "*/src/manager/some_util.py", line 23, in <module>
some_url, some_user, some_pass = load_some_config()
File "*/src/manager/some_util.py", line 9, in load_some_config
some_configs = Property.query.filter(Property.name.contains(‘MANAGER’)).all()
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 514, in __get__
return type.query_class(mapper, session=self.sa.session())
File "*/venv/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 78, in __call__
return self.registry()
File "*/venv/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 990, in __call__
return self.registry.setdefault(key, self.createfunc())
File "*/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2882, in __call__
return self.class_(**local_kw)
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 141, in __init__
self.app = app = db.get_app()
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 912, in get_app
'No application found. Either work inside a view function or push'
RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
To execute some code within the Flask app context, the most simple way is doing this:
with self.app.app_context():
# ... your code here ...
Note that app is your Flask application object. The variable name might be different in your case.

Resources