I want my bot to be able to say a message, mention a user, then respond with a random message, all in the same line, as opposed to having it in 3 separate lines.
This was my previous method:
JavaScript
x
5
1
if msg.startswith('respond')
2
await message.channel.send('alright then,')
3
await message.channel.send(message.author.mention)
4
await message.channel.send(random.choice(responses))
5
However, this makes them all appear in the same line, but I can’t figure out how to merge them into a singular line. This was one of my many failed attempts:
JavaScript
1
3
1
if msg.startswith('respond'):
2
await message.channel.send ('alright then, <message.author.mention> <random.choice(responses)>')
3
(please don’t make fun of my amateur coding skills lmao)
Advertisement
Answer
assuming you are using python3+, you could do f-strings
JavaScript
1
3
1
if msg.startswith('respond'):
2
await message.channel.send(f'alright then, {message.author.mention} {random.choice(responses)}')
3
there are other alternatives to this, such as format strings
JavaScript
1
3
1
if msg.startswith('respond'):
2
await message.channel.send('alright then, {} {}'.format(message.author.mention, random.choice(responses))
3
concatenation methods like
JavaScript
1
3
1
if msg.startswith('respond'):
2
await message.channel.send('alright then, ' + message.author.mention + ' ' + random.choice(responses))
3