好吧,所以我制作了一个Discord Bot,它从reddit中获取模因,并每5分钟将其发送到用户指定的频道,为此,我必须制作一个cog
#imports
import discord
...
...
#Automemer
class Automemer(commands.Cog):
def __init__(self, client):
....
#used to loop the task of posting memes
@tasks.loop(minutes=5.0)
async def automemer(self):
all_subs = []
...
#start of formating embed for task loop
name = random_sub.title
url = random_sub.url
em = discord.Embed(title = name)
em.set_image(url = url)
em.color = 0xff0000
em.set_footer(text=f'Memes from r/AmongUsMemes')
#used to post the memes where the user does the command am.memechannel
@commands.command()
async def memechannel(self, ctx):
channel_id = ctx.channel.id
await ctx.send('Memes will now be sent in this channel')
memeChannel = ctx.guild.get_channel(channel_id)
if memeChannel:
emoji1 = ':arrow_up:'
emoji2 = ':arrow_down:'
msg = await ctx.send(embed=em)
await msg.add_reaction(emoji1)
await msg.add_reaction(emoji2)
await ctx.send(embed=em)
Error = Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "memechannel" is not found
每当我运行命令am.memechannel时,都会发生错误。
如果有人告诉我如何解决此错误,那就太好了。 这是该机器人的最后一个功能,这将是我第一次向公众发布Discord Bot! :)
答案 0 :(得分:0)
您在任务循环中定义了命令,缩进变得混乱了。您应该将命令放在下面,而不是放在循环内部。
HttpSession session = request.getSession();
KeyPair pair = (KeyPair) session.getAttribute("keypair");
Cipher cipher = (Cipher) session.getAttribute("cipher");
String password = (String) session.getAttribute("password");
String filename = (password +".txt");
File dir = new File("/volume");
dir.mkdir();
File myfile = new File(dir, filename);
byte[] encryptedBytes = bytesFileReader(myfile);
try {
cipher.init(Cipher.DECRYPT_MODE, pair.getPrivate());
byte[] decipheredText = cipher.doFinal(encryptedBytes);
System.out.println(new String(decipheredText, StandardCharsets.UTF_8));
} catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
e.printStackTrace();
}
}
请记住,@tasks.loop(minutes=5.0)
...
@commands.command()
...
变量仅在任务中可见,因此您必须找到一种解决方法,否则您将无法在命令中使用它。一个示例就是将其添加为类变量。
em
然后随便覆盖该变量。
def __init__(self, client):
self.em = discord.Embed()