#python #discord.py #message
#питон #discord.py #Сообщение
Вопрос:
Я хочу отправить сообщение как «1», а не » [«1″]». Вот код:
@client.command() async def add(message, *args): numz = "" for arg in args: numz = numz "" arg numz = numz.split() num = [item[0] for item in numz] num1 = [item[1]for item in numz] numm = num num1 zembed = discord.Embed( title="Here's The Answer: ", description=str(num) ' ' str(num1) ' = ' str(numm), url="", color=discord.Color.blue() ) await message.send(embed=zembed)
Вот сообщение для вставки: ['4'] ['5'] = ['4', '5']
Ответ №1:
Предполагая add
, что это
@client.command() async def add(message, *args): answer = add_args(args) zembed = discord.Embed( title="Here's The Answer: ", description=answer, url="", color=discord.Color.blue() ) await message.send(embed=zembed)
и ваш код должен
- суммируйте аргументы в виде чисел, вы можете сделать
def add_args(*args): # Join the arguments using ' ' as separator ('4 5 6') l_arg = ' '.join(args) # Map the arguments to integers and sum them (4 5 6 = 15) r_arg = sum(map(int, args)) return f"{l_arg} = {r_arg}" print(add_args('4', '5')) # Outputs 4 5 = 9
- присоединяйтесь к аргументам в виде строк, вы можете сделать
def add_args(*args): # Join the arguments using ' ' as separator ('4 5 6') l_arg = ' '.join(args) # Join the arguments using '' as separator ('456') r_arg = ''.join(args) return f"{l_arg} = {r_arg}" print(add_args('4', '5')) # Outputs 4 5 = 45