Buttons not working in Discord Py 2.0. When you click on the button, it displays the error below - discord

Here is the code:
class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
#discord.ui.button(label="Blurple Button", style=discord.ButtonStyle.blurple) # or .primary
async def blurple_button(self, button : discord.ui.Button, interaction: discord.Interaction):
print('1')
button.disabled = True
await interaction.response.edit_message(view=self)
Here is the error:
Bot connection
1
2023-02-03 23:47:15 ERROR discord.ui.view Ignoring exception in view for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Blurple Button' emoji=None row=None>
Traceback (most recent call last):
File "D:\Andrej\3.Project\venv\Lib\site-packages\discord\ui\view.py", line 425, in _scheduled_task
> await item.callback(interaction)
File "D:\Andrej\3.Project\Ecumonopolis 1.0\ecumenopolis ORM.py", line 506, in blurple_button
> button.disabled = True
^^^^^^^^^^^^^^^
AttributeError: 'Interaction' object has no attribute 'disabled'
Help me please. And help me figure out the buttons in Discord Py 2.0
Thank you in advance!
Help me please. And help me figure out the buttons in Discord Py 2.0
Thank you in advance!

button.disabled = True
AttributeError: 'Interaction' object has no attribute 'disabled'
As the error is telling you, your button argument is actually an Interaction, and vice-versa. You've got your arguments the wrong way around.
There are official examples for views & buttons if you need them.
The tags in your post also suggest you're using a third-party package for buttons. There's no need for that, everything is built-in into discord.py.

Related

discord.ext.commands.errors.CommandNotFound: Command is not found [solved]

I finished a bot after a couple of hours and while trying to run it I get this error message 'discord.ext.commands.errors.CommandNotFound: Command "play" is not found' I don't know why/ how to fix this could anyone help?
The chunk of code with the error will be below this text:
#commands.command()
async def play(self,ctx,url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
ask me if you need more of the code/more of the terminal output
I tried running the bot multiple times and I've looked around overflow for an answer and found nothing :/
(Comments mentioned you didn't load your cogs)
discord.py can't just "know" that it has to load your cogs, you have to do this yourself. This works through the process of extensions.
Extensions are loaded using load_extension. The best place to do this is setup_hook (don't use something like on_ready!). An extension is a file with a setup() method, which is invoked by the library when you call load_extension(). You can use this function to attach the cog to your bot.
Loading the extension in your bot's file:
class MyBot(commands.Bot):
...
async def setup_hook(self):
# This is typically done by looping over a directory of Cog files
# instead of 1 by 1, but this is just an example
await self.load_extension("path.to.your.extension")
Attaching the Cog in your extension's file:
class MyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def setup(bot):
await bot.add_cog(MyCog(bot))

How to detect a discord message being edited (but not updated)?

I'm using Node and Discord.JS, trying to see if there's a way to differentiate between types of edits whenever a message is edited so a bot can tease the user for editing their message. The function works well so far, and is as follows:
let responses = ["some", "responses"];
bot.on('messageUpdate', ( message ) => {
let result = responses[Math.floor(Math.random()*(responses.length)-1)]
message.channel.send(result);
})
However, this detects all message updates, including say a link updating to have an embed. Is there any way to differentiate between a deliberate user edit and a message being updated with an embed through event listeners, or will I need to make a workaround with an if..else statement?
To check when message is edited, You'll be required to use the messageUpdate event listener.
In the messageUpdate event, there is 2 parameters. (oldMessage, newMessage) Learn More
Then, you can check the content of the oldMessage & newMessage parameters by using the .content property.
Example of code:
client.on("messageUpdate", (oldMessage, newMessage) => {
if(oldMessage.content === newMessage.content) return // Will do nothing if the content of oldMessage is equals to newMessage's content
// Do here your stuff
})
I hope I helped you!
Ignore this, i have not found an answer as I had hoped ;(

I'm trying to make my bot give a role to someone that uses the command but it says "AttributeError: 'tuple' object has no attribute 'id'"

I'm a complete beginner so can someone please explain me what is wrong here and how to fix it? Thank you
from discord.ext import commands
from discord.utils import get
#client.command()
async def reserve(message, *, stand):
channel = message.channel,
author = message.author,
guild = message.guild,
the_world = get(message.guild.roles,name="The World"),
if stand == 'The World':
await message.author.add_roles(the_world)
The error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'tuple' object has no attribute 'id'
Assuming as the rest of your bot runs, your provided code causes this error as you are using get(ctx.guild.roles,name="The World") instead, make sure to use discord.utils in your argument:
discord.utils.get(ctx.guild.roles,name="The World")
Additionally I've modified some more of your code, as a command, you don't need to pass message as your parameters, use ctx and it's attributes.
#client.command()
async def reserve(ctx, *, stand):
if stand == 'The World':
the_world = discord.utils.get(ctx.guild.roles,name = "The World"),
await ctx.author.add_roles(the_world)

Having Issues with "Client" inside MessageEmbed

Code:
const specifyembed = new Discord.MessageEmbed()
.setAuthor("Auto-Partner", client.user.displayAvatarURL())
.setThumbnail(client.user.displayAvatarURL())
.setDescription("**__Want to grow fast?__** \nWith this bot you can gain up to **3,000 Members** per week! \nThis bot will share your server in many active servers and to many active users! \nSimply add me to your server and use the command ``-partner {MESSAGE}``")
.addFields([
{
name: '**__Bot Invite Link:__**',
value: '[- Click To Add Bot -](your link goes here)'
}
])
.setTimestamp()
.setFooter("© Auto-Partner")
if(!args[0]) return message.channel.send(specifyembed)
Error:
(node:7920) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined
So if anyone got any solutions on how to fix this please help me out.
Issue was in util.js and command handler, i havent connected util.js with command handler, depends on what your issue is hopefully this one helps, i know it can depend.

app-engine-patch and pyFacebook not working

I am trying to write a facebook app using app-engine-patch and pyFacebook.
I am using nothing but the examples provided with each tool and for some reason it will not work.
I have combined the two just as described in the accepted answet here:
Facebook, Django, and Google App Engine
app-engine-patch seems to work just fine but when I try to use #facebook.require_login() I get this from GAE's logs:
Exception in request:
Traceback (most recent call last):
File "/base/data/home/apps/app-name/1.339079629847560090/common/zip-packages/django-1.1.zip/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/djangofb/__init__.py", line 87, in newview
if not fb.check_session(request):
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/__init__.py", line 1293, in check_session
self.session_key_expires = int(params['expires'])
ValueError: invalid literal for int() with base 10: 'None'
This happends no matter which view I decorate with #facebook.require_login()
I am using the latest from both projects and I have no idea why it wont work.
Many thanks for your time.
UPDATE: I made a quickfix for pyFacebook, but I just forgot to put it back in the thread.
Now also as an answer, since it seems to be the only way.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will work, but it is a hack and maybe it could be done more elegantly, but it works.
Gotta point the pyFacebook devs to this thread, maybe they will have a better solution.
You should not use pyfacebook's decorator #facebook.require_login() when using pyfacebook with facebook-connect. The decorator is meant to be used for a facebook application, as it redirects the user to the facebook site if they are not logged in, but you really want to redirect the user to your login page on your site if they are not logged in.
To check if someone is logged in with facebook-connect and pyfacebook with the djangofb middleware, you call request.fb.check_session(request). If check_session returns True then they have a valid session. If it returns False then you need to redirect the user to your login page so they can click the facebook connect login button you (should) have placed on that page.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will work, but it is a hack and maybe it could be done more elegantly, but it works.

Resources