P
P
Pepegio2021-11-10 16:28:19
Python
Pepegio, 2021-11-10 16:28:19

User argument in variable?

It is necessary that when writing the /lastmap <link> command, it remembers the link and displays it when writing the /map command, but how to do this? Tried many different ways but it didn't work for me.

@slash.slash(name = 'lastmap', description = 'последняя версия карты', options = [{"name": "ur", "description": "ссылка", "type": 3, "required": True}], guild_ids = [907669402181316638])
@client.command(aliase = ['lastmap'])
@commands.has_any_role(907669402181316638)
async def lastmap(ctx, *, ur):
  id = ctx.author.display_name
  ur = {ur}
  embedVar = discord.Embed(title="Карта", description=f"{id}, карта обновлена, ссылка: {ur}")
  embedVar.set_image(url='https://media.discordapp.net/attachments/902258027648917524/907969211312271360/unknown.png')
  await ctx.send(embed=embedVar)    

@slash.slash(name = 'map', description = 'последняя версия карты', options = [{"name": "text", "description": "текст", "type": 3, "required": True}], guild_ids = [907669402181316638])
@client.command(aliase = ['map'])
@commands.has_any_role(907669402181316638)
async def map(ctx, *, text):
  id = ctx.author.display_name
  embedVar = discord.Embed(title="Карта", description=f"Держи карту, {id}. Только зачем ты написал {text}?")
  embedVar.set_image(url=f'{ur}')
  await ctx.send(embed=embedVar)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-11
@Pepegio

If the link is single and short-lived:

current_url = None #храним ссылку в глобальной переменной
@slash.slash(name = 'lastmap', description = 'последняя версия карты', options = [{"name": "ur", "description": "ссылка", "type": 3, "required": True}], guild_ids = [907669402181316638])
@client.command(aliase = ['lastmap'])
@commands.has_any_role(907669402181316638)
async def lastmap(ctx, *, ur):
  global current_url
  id = ctx.author.display_name
  current_url = ur
  embedVar = discord.Embed(title="Карта", description=f"{id}, карта обновлена, ссылка: {current_url}")
  embedVar.set_image(url='https://media.discordapp.net/attachments/902258027648917524/907969211312271360/unknown.png')
  await ctx.send(embed=embedVar)    

@slash.slash(name = 'map', description = 'последняя версия карты', options = [{"name": "text", "description": "текст", "type": 3, "required": True}], guild_ids = [907669402181316638])
@client.command(aliase = ['map'])
@commands.has_any_role(907669402181316638)
async def map(ctx, *, text):
  global current_url
  id = ctx.author.display_name
  if current_url: #проверяем, задана ли карта
    embedVar = discord.Embed(title="Карта", description=f"Держи карту, {id}. Только зачем ты написал {text}?")
    embedVar.set_image(url=f'{current_url}')
    await ctx.send(embed=embedVar)
  else:
    await ctx.send(f"Извини, {id}, карта ещё не задана.")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question