How can I add variables in my class? #2083
-
Hi, how can I extend the class with my variables? When I try the folloing code the the function, on message exits with the error "list with draft chabbels" is not defined, I tried also without self and with bot.list_xxx but always the same error. Any help? class MyBot(commands.Bot): bot = MyBot() @bot.event |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
To start off, the GitHub discussions tab is not intended for help-related questions: please ask in our Discord server, instead. Assuming that the indentation is correct, As a result, you can use the object to access its attribute: |
Beta Was this translation helpful? Give feedback.
-
Hi ,
Thank you for your reply but I mentioned in my message that I have used the
bot.syntax but I have the same error that the class does not have an
element with the name list_xxx
…On Sun, 21 May 2023 at 00:47, JustaSqu1d ***@***.***> wrote:
To start off, the GitHub discussions tab is intended for help-related
questions: please ask in our Discord server <https://discord.gg/pycord>,
instead.
Assuming that the indentation is correct, self.list_with_draft_channels
will not work because self is not defined. self is used to refer to the
object of the creation, however, outside of the class, you would use the
variable that refers to the object itself (in this case, bot).
As a result, you can use the object to access its attribute:
bot.list_with_draft_channels.
—
Reply to this email directly, view it on GitHub
<#2083 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNXJ7QBZPBRUHKGZTINCODXHFCWVANCNFSM6AAAAAAYI7VGAY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I will try it out tomorrow.
…On Sun, 21 May 2023 at 01:03, JustaSqu1d ***@***.***> wrote:
Hey, sorry for the ambiguity. I have attached an example of what my
solution would look like.
class MyBot(commands.Bot):
def __init__(self):
self.list_with_draft_channels = [0]
super().init(command_prefix=BOT_PREFIX, intents=discord.Intents.all()) #pass arguments to the parent class
print("Mybot")
bot = MyBot()
@bot.event
async def on_message(message):- print(self.list_with_draft_channels)+ print(bot.list_with_draft_channels)
—
Reply to this email directly, view it on GitHub
<#2083 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNXJ7WGSBFSICNA7VYMZELXHFEVNANCNFSM6AAAAAAYI7VGAY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Please join our support server |
Beta Was this translation helpful? Give feedback.
To start off, the GitHub discussions tab is not intended for help-related questions: please ask in our Discord server, instead.
Assuming that the indentation is correct,
self.list_with_draft_channels
will not work becauseself
is not defined.self
is used to refer to the object of the creation, however, outside of the class, you would use the variable that refers to the object itself (in this case,bot
).As a result, you can use the object to access its attribute:
bot.list_with_draft_channels
.