【发布时间】:2021-09-16 10:26:20
【问题描述】:
我想让这个 discord bot 可以 ping、portscan 和 whois 服务器和 IP。所有命令都可以正常工作,但是当我尝试使用 pythonping 时,我得到一个我看不到的错误。我得到这个不和谐的消息,<coroutine object Command.call at 0x04E55368> 和 Visual Studio Code 终端中的这个错误我得到这个错误,C:\Users\swevl\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py:85: RuntimeWarning: coroutine 'Command.__call__' was never awaited ret = await coro(*args, **kwargs) RuntimeWarning: Enable tracemalloc to get the object allocation traceback。
这是我的代码:
from discord.ext import commands
import json
import os
import random
import string
import time
import colorama
from colorama import Fore, Back, Style
import string
from os import system, name
import aiohttp
from pythonping import ping
import requests
# # # # # # # # # # Bot Config and Token # # # # # # # # # #
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
clear()
os.system("cls && title Gen Bot")
token = "Censored Bot Token"
client = commands.Bot(command_prefix='a!', case_insensitive=True)
client.remove_command('help')
print(f" {Fore.RED}╔═╗╦ ╔═╗╦ ╦╔═╗ ╔╗ ╔═╗╔╦╗")
print(f" {Fore.RED}╠═╣║ ╠═╝╠═╣╠═╣ ╠╩╗║ ║ ║ ")
print(f" {Fore.RED}╩ ╩╩═╝╩ ╩ ╩╩ ╩ ╚═╝╚═╝ ╩ ")
print(f"{Fore.YELLOW}I-----------------------------------------------------I")
@client.event
async def on_ready():
# login of client
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='a!help'))
print(f"{Fore.RED}[{Fore.YELLOW}STATUS{Fore.RED}] The bot just went online!".format(client))
#####Utiity Commands#####
@client.command()
async def clear(ctx, amount=100):
await ctx.channel.purge(limit=amount)
await ctx.send("Messages have been removed!", delete_after=4)
print (f'{Fore.RED}[{Fore.YELLOW}LOGS{Fore.RED}] {ctx.author} cleared {amount} messages')
#########################################################################################################################################
@client.command(name='whois')
async def whois(ctx, arg1):
if arg1 == "":
await ctx.send("Invalid IP!")
else:
async with aiohttp.ClientSession() as session:
async with session.get(f"http://ip-api.com/json/{arg1}?fields=66846719") as r:
js = await r.json()
myip = ('')
if myip == (js["query"]):
await ctx.send('Invalid Ip!')
else:
cont = (js["continent"])
country = (js["country"])
region = (js["regionName"])
city = (js["city"])
zipcode = (js["zip"])
iso = (js["isp"])
org = (js["org"])
reverse = (js["reverse"])
mobile = (js["mobile"])
proxy = (js["proxy"])
hosting = (js["hosting"])
embed1 = discord.Embed(title=(js["query"]), color = discord.Color.red())
embed1.add_field(name="info", value=(f"{ctx.author.mention}\n"
f"Continent: {cont} \n"
f"country: {country} \n"
f"Region: {region}\n"
f"City: {city} \n"
f"Zip: {zipcode} \n"
f"ISP: {iso} \n"
f"Org: {org} \n"
f"Reverse: {reverse} \n"
f"Mobile: {mobile} \n"
f"Proxy: {proxy} \n"
f"Hosting: {hosting}"), inline=False)
await ctx.send(embed=embed1)
print (f'{Fore.RED}[{Fore.YELLOW}LOGS{Fore.RED}] {ctx.author} used the whois comand on {arg1}')
@client.command()
async def portscan(ctx, arg1):
if arg1 == '':
await ctx.send("Invalid IP!")
else:
print (f'{Fore.RED}[{Fore.YELLOW}LOGS{Fore.RED}] {ctx.author} portscanned {arg1}')
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.hackertarget.com/nmap/?q={arg1}") as r:
if r.status == 200:
text = await r.text()
embed1 = discord.Embed(title=(f'Results from {arg1}'), description=(text), color = discord.Color.red())
await ctx.send(embed=embed1)
else:
await ctx.send("API is offline, try again later...")
@client.command()
async def ping(ctx, arg1):
if arg1 == '':
await ctx.send("Invalid IP!")
else:
await ctx.send(ping(arg1))
client.run(token)```
【问题讨论】:
-
你能告诉我这个错误在我的代码中的什么地方吗?
标签: python discord discord.py ip ping