【发布时间】:2018-05-13 02:49:50
【问题描述】:
我正在为我的一个朋友制作一个discord.py 机器人。我想这样做,以便您可以将愚蠢的引号添加到列表中,然后随机选择它们。这么多,我已经完成了。
但是,我还希望能够删除不相关、拼写错误等的引号。我想知道如何做到这一点。
这是我目前得到的:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import random
import pickle
import os
Client = discord.Client()
bot_prefix = "."
bot = commands.Bot(command_prefix=bot_prefix)
@bot.event
async def on_ready():
print("Bot Online!")
print("Name: {}".format(bot.user.name))
print("ID: {}".format(bot.user.id))
class Main_Commands():
def __init__(self, bot):
self.bot = bot
# .addquote
@bot.command(pass_context = True)
async def addquote(ctx, *answer):
answer=" ".join(answer)
if not os.path.isfile("quote_file.pk1"):
quote_list = []
else:
with open("quote_file.pk1", "rb") as quote_file:
quote_list = pickle.load(quote_file)
quote_list.append(answer)
with open("quote_file.pk1", "wb") as quote_file:
pickle.dump(quote_list, quote_file)
await bot.say('Quote: "{}" added!'.format(answer))
# .quote
@bot.command(pass_context = True)
async def quote(ctx):
with open("quote_file.pk1", "rb") as quote_file:
quote_list = pickle.load(quote_file)
await bot.say(random.choice(quote_list))
bot.run("TOKEN")
基本上,我想添加另一个函数.removequote(),它可以删除特定的引用,同时保持其他引用不变。
【问题讨论】:
标签: python bots discord discord.py