What i'm trying to achive is to make three simple commands:
!add nick
!delete nick
!list (of nicknames)
This is my not-so-well-working script:
import json
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
def add(name):
list.append( name )
@bot.command()
async def dele(ctx, *args):
with open('list.json', 'r') as f:
lines = json.loads(f.read())
for name in args:
lines.remove(name)
with open('list.json', 'w') as f:
f.write(json.dumps(lines))
@bot.command()
async def add(ctx, *args):
with open('list.json', 'r') as f:
lines = json.loads(f.read())
for name in args:
lines.append(name)
with open('list.json', 'w') as f:
f.write(json.dumps(lines))
@bot.command()
async def list(ctx):
with open('list.json', 'r') as f:
list = json.loads(f.read())
await ctx.channel.send(f"List {list}")
bot.run("MY TOKEN HERE")
Command !list output:
list.json
["test1", "test2", "test3", "test", "4", "test4", "name", "name", "test", "5", "test", "6"]
So... adding and deleting nicknames works fine (except that when i'm trying to add nickname with spaces its adding two separate keys).
But the biggest problem i got with the list command. Don't know how to format this to some kind of list with \n nicknames showing one by one or even with discord embed thing. Please help.
