Answer the question
In order to leave comments, you need to log in
Discord.py How to output a variable in one command to another?
I have a variable in one command and I need to output it from another, I tried to use global, but nothing has changed, an error occurs that the moder variable is missing.
@client.command()
async def _init_( ctx ):
global moder
embed = discord.Embed(
title = 'Это мой заголовок',
description = 'Это мой основной текст',
color = 0x83c837
)
moder = await ctx.send(
embed = embed
)
@client.command()
async def test( ctx ):
global moder
await ctx.send(
moder
)
Answer the question
In order to leave comments, you need to log in
If you want to use globals, the variable must initially be declared outside of any functions
Make moder a global variable
moder = None
@client.command()
async def _init_( ctx ):
global moder
embed = discord.Embed(
title = 'Это мой заголовок',
description = 'Это мой основной текст',
color = 0x83c837
)
moder = await ctx.send(
embed = embed
)
@client.command()
async def test( ctx ):
await ctx.send(
moder
)
In this case, you need to use Class
class MyClass:
@client.command()
async def _init_(sefl,ctx):
self.moder = None
embed = discord.Embed(
title='Это мой заголовок',
description='Это мой основной текст',
color=0x83c837)
self.moder = await ctx.send(embed=embed)
@client.command()
async def test(sefl,ctx):
await ctx.send(
self.moder
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question