import random
import asyncio
import aiohttp
import json
from discord import Game
from discord.ext.commands import Bot
import discord
TOKEN = 'Token'
client = discord.Client()
botnum = 0
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('PeriBot'):
msg = "I'm Busy! D:<".format(message)
await client.send_message(message.channel, msg)
if discord.message and botnum == 20
msg = "You Clods are so loud!".format(message)
await client.send_message(message.channel, msg)
set botnum == 0
else:
botnum + 1
@client.event
async def on_ready():
print('Online and Ready to Play!')
print(client.user.name)
print(client.user.id)
await client.change_presence(game=discord.Game(name="With Emotions"))
print('------')
client.run("Token")
我希望它每 20 条消息说一条消息,但我不确定该怎么做。我有一个名为 botnum 的东西,它是 == 0,如果没有 20 个 botnum,那么它将向 botnum 添加 1。如果有 20 个,则表示一条消息。我希望它在每个 msg 中给 botnum 加 1。
请您参考如下方法:
我注意到您的代码中有很多语法错误,我已经在下面对其进行了更新,使其看起来应该是什么样子,并在修改的行末尾用### 标记了更改。至于“让他们注意到每条消息”,我需要澄清一下,如果这不符合您的需要,我会更新我的答案。我认为我刚刚提供的代码应该在每次发送不是 PeriBot 的消息时将 botnum 更新为 1,这应该可以解决您的问题。
import random
import asyncio
import aiohttp
import discord
import json
from discord import Game
from discord.ext.commands import Bot
TOKEN = 'Token'
client = discord.Client()
@client.event
async def on_ready():
print('Online and Ready to Play!')
print(client.user.name)
print(client.user.id)
await client.change_presence(game=discord.Game(name="With Emotions"))
print('------')
botnum = 0
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
elif message.content.startswith('PeriBot'): ### Updated to elif which is more acceptable
msg = "I'm Busy! D:<".format(message)
await client.send_message(message.channel, msg)
elif discord.message and botnum == 20: ### forgot a ":" and Updated to elif which is more acceptable
msg = "You Clods are so loud!".format(message)
await client.send_message(message.channel, msg)
botnum = 0 ### you were comparing and not setting botnum to 0
else:
botnum += 1 ### This will add 1 to the preexisting number of botnum
client.run("Token")
