python - Discord Bot 在不应该的情况下随机发送多次命令
问题描述
我创建的不和谐机器人应该在有人打招呼时被激活,但是当这种情况发生时,会发送多个输出。我知道 discord.py 所以这可能是一个愚蠢的问题,但是很容易解决,但不确定如何做到这一点:
import discord
bot = discord.Client()
@bot.event
async def on_ready():
guild_count = 0
for guild in bot.guilds:
print(f"- {guild.id} (name: {guild.name})")
guild_count = guild_count + 1
print("SampleDiscordBot is in " + str(guild_count) + " guilds.")
@bot.event
async def on_message(message):
if message.content == "hello":
await message.channel.send("hey")
if message.content == "what is your wisdom o' truth bot":
await message.channel.send("Stupid, this is!")
bot.run('KEY')
解决方案
推荐阅读
- flutter - 消费者和提供者的问题
- javascript - JavaScript 正则表达式立即结束不应该是数字
- mysql - MySQL重复行并更新旧行和新行
- vue.js - 在 VueJS 上使用 Jest 模拟 .get() 函数
- javascript - Ramda - 如何验证对象?
- xcode - 在哪里可以找到有关遇到的错误类型的更多信息?
- cygwin - 尝试生成 Doxygen 文档时出现“权限被拒绝”错误
- matrix - 将矩阵中的每个偶数除以 2
- php - "Gitpod" 将默认 PHP v7.4.3 降级到 7.1.3 或 7.2
- javascript - 在javascript中从CSV字符串转换为Json