【发布时间】:2021-03-22 12:08:01
【问题描述】:
我是这方面的新手,机器人会一个接一个地发送每个坏词直到它完成,这真的很烦人。这是代码。
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.author.bot:
return
with open('badwords.txt') as file:
file = file.read().strip()
for badwords in file:
if badwords in message.content.lower():
msg = await message.channel.send(f'{message.author.mention}Please avoid using malicious and insulting words in the future! words you used: {badwords}',delete_after=10)
await msg.add_reaction('<a:cRight:819401530964836382>')
await msg.add_reaction('<a:Heart:819401449095692309>')
await msg.add_reaction('<a:cLeft:819403565440827423>')
await message.channel.send('messages delete after 10 seconds',delete_after=5)
guild = message.guild
role = discord.utils.get(guild.roles, name="Muted")
await message.author.add_roles(role)
embed = discord.Embed(title="Muted!", description=f"{message.author.mention} Muted for 1 minute", colour=discord.Colour.blue())
embed.add_field(name="reason",value=f"Badwords moderation, word that was used: {badwords}",inline=False)
await message.channel.send(embed=embed,delete_after=300)
await asyncio.sleep(60)
await message.author.remove_roles(role)
embed = discord.Embed(title="Unmuted", description=f"Unmuted - {message.author.mention} ", colour=discord.Colour.blue())
await message.channel.send(embed=embed,delete_after=300)
await client.process_commands(message)
我正试图让机器人在一条消息中发送所有坏话,就像在代码中一样, 机器人会发送一条消息并静音,但它会根据消息中有多少坏词重复,并且还会重复静音在她/他的消息中使用坏词的用户。 代码没有问题,它工作得非常好,我要求你进行更改,无论消息中有多少坏词,都只让机器人发送一次,并且还要列出机器人发送的消息中的坏词。
在图像中它会重复直到发送完所有单词,我完全不知道应该添加或更改什么以使机器人编译每个坏词并发送嵌入并静音使用过的用户坏话
(忽略这一点,似乎堆栈溢出一直在告诉我添加细节......我正在填充它) 我在这段代码中使用了打开文件的方法,请帮助和 ps 我是新手不要说我不好,我还在 14 岁学习编码:) 我会很高兴有人会帮助我:)
【问题讨论】:
标签: python discord.py