这是我的代码
import discord
import asyncio
import sys
import commands
import pickle
import os
import random
import array
#if len(sys.argv) != 2:
# print('Usage: python3 main.py [token]')
commandz=("yes","no","hi","hi")
try:
with open(os.path.join(os.path.dirname(__file__), "token.pickle"), 'rb') as file:
token = pickle.load(file)
if len(token) == 59:
key = int(random.random() * 10000000000000000)
print('Found saved token in stored.py, use phrase tokenreset'+str(key), 'to undo this.')#youll need to add the command
else:
raise
except:
#code tokenreset with admin permissions
token = input('What is your Discord bot token? (found on Discord developer page): ')
with open(os.path.join(os.path.dirname(__file__), "token.pickle"), 'wb') as file:
pickle.dump(token, file)
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as' + '[' + client.user.id + ']' + client.user.name)
print('--------')
@client.event
async def on_message(message):
await handle_command(message)
async def handle_command(message):
print('Noticed: ' + message.content)
if message.content == 'tokenreset'+str(key):
await client.send_message(message.channel, 'code accepted')
i = 0
if str(message.author) == "NOTAKOALAINVENEZUELA#6895":
i = 1
x = 0
await client.send_message(message.channel, message.author)
while i == 0:
if commandz[x] in message.content:
x = x + 1
await client.send_message(message.channel, commandz[x])
i = i + 1
else:
if x == len(commandz) - 2:
i = i + 1
else:
x = x + 2
client.run(token)
结果是我的机器人一遍又一遍地触发它自己的命令,我已经尝试了一切让它不能识别它自己的消息而且我在我的智慧结束。
我认为由于某种原因,message.author是一些奇怪的变量,不能用于比较,我是编程和python的新手,所以我不确定。
答案 0 :(得分:0)
您可以尝试使用以下方法检查作者是否是机器人:
city age
mumbai 12 33 5 55 14 56 78 99 34 59
delhi 24 56 78 23 43 55 67
kal 12 43 55 78 34 11
这样你可以确定机器人不会触发它。