Reputation: 13
So, I've a command set on my bot that whenever someone types "/planeidea" it sends the name of a plane, however, i've like 300 lines of names of planes. (I reduced it, so you can see an example of what im talking about). What i wanna do is make a .txt file and place all the names of the planes instead of having it in the main code.
@client.command()
@commands.cooldown(1, 5, commands.BucketType.user)
async def planeidea(ctx):
responses = ("P-51", "Me-109", "Spitfire", "Handley Page Hampden",
"Avro lanson",
"Fairy battle",
"Bristol Bleinheim",
"B24 liberator",
"B26 marauder",
"A20 Havoc",
"Bristol beaufort",
"Short stirling",
"Lockheed hudson",
"Avro york",
"PBY Catalina",
"Brewster SB2A Buccaneer",
"Avro manchaster",
"Heinkel he 111Z",
"Dornier do 17",
"Dornier do 217",
"Dornier do 317",
"Junkers ju 188",
"Junkers ju 288",
"Junkers ju 388",
"Junkers ju 488",)
reply = random.choice(responses)
mama = discord.Embed(title=f"Plane idea machine:",description=(reply), color=0xe74c3c)
await ctx.send(embed=mama)
I don't know if you understand what i'm saying, i'm a newbie on this.
Upvotes: 1
Views: 262
Reputation: 1318
Alright, so you can just create a plain text file, for my example, I'll just use planes.txt
. Inside planes.txt
, I can just list my planes line by line with no quotations or commas:
P-51
Me-109
etc...
Inside of my code, I can just open the text file and split the lines to make myself a list:
with open("planes.txt", "r") as planes:
responses = planes.read().splitlines()
Upvotes: 2