[英]Is there any way I can make my discord bot send same messages(without skipping the older messages) in different servers
对不起,但我无法正确地提出问题。 目前,当有人在一台服务器上使用我的“模因”命令时,它会显示模因,但是如果来自另一台服务器的人使用相同的命令,我的机器人会跳过它已经显示的模因。 我是编程新手,有人能告诉我如何解决这个问题并解释他们做了什么吗?谢谢!
@client.command()
async def meme(ctx, typememe="hot"):
if typememe == "hot":
y = next(hot_memes)
x = y.url
z = y.title
votes = y.score
comments = y.num_comments
embed = discord.Embed(
colour=discord.Colour.blue(),
title=z,
url=x
)
embed.set_image(
url=x)
embed.set_footer(
text=f"Upvotes:{votes}"
)
await ctx.send(embed=embed)
elif typememe == "controversial":
y = next(controversial_memes)
x = y.url
z = y.title
votes = y.score
comments = y.num_comments
embed = discord.Embed(
colour=discord.Colour.blue(),
title=z,
url=x
)
embed.set_image(
url=x)
embed.set_footer(
text=f"Upvotes:{votes}"
)
await ctx.send(embed=embed)
我要做的是有一个字典来存储公会 ID 和调用 meme 命令的时间,比如{GUILD_ID,4}
其中 4 是调用“meme”的时间,我们将其称为记忆存储。 之后,每次调用 meme 命令时,您都可以使用memestorage.keys()
检查它是否在 memestorage 的密钥中,如果不在,则使用memestorage[ctx.message.guild] = 0
添加它。 最后,将 integer 添加到 memestorage 中位于 ctx.message.guild 的 integer 并在该索引 + 1 处获取模因。所有这些加在一起可能看起来像:
memestorage = {}
memeiter = [meme1,meme2,meme3,meme4]
@client.command()
async def meme(ctx):
guild = ctx.message.guild
if guild not in memestorage.keys():
memestorage[guild] = 0
memestorage[guild] += 1
if memestorage[guild] >= len(memeiter):
memestorage[guild] = 1
pickedmeme = memeiter[memestorage[guild]+1]
有了这个,您还可以将内存存储字典保存在 json 文件中,这样即使机器人离线也可以存储数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.