Spaces:
Paused
Paused
File size: 1,460 Bytes
2fd3032 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """
测试 Discord API 连接
"""
import asyncio
import aiohttp
async def test_discord_connection():
"""测试能否连接到 Discord API"""
print("=" * 50)
print("Discord API 连接测试")
print("=" * 50)
print()
try:
print("正在测试网络连接...")
# 测试基本网络连接
async with aiohttp.ClientSession() as session:
async with session.get('https://discord.com/api/v10/gateway', timeout=10) as response:
if response.status == 200:
print("✅ 可以连接到 Discord API")
data = await response.json()
print(f" Gateway URL: {data.get('url', 'N/A')}")
else:
print(f"❌ 连接失败,状态码: {response.status}")
return False
print()
print("=" * 50)
print("🎉 网络连接正常!")
print("=" * 50)
return True
except Exception as e:
print(f"❌ 连接失败: {e}")
print()
print("可能的原因:")
print(" 1. 网络连接问题")
print(" 2. 防火墙阻止")
print(" 3. DNS 解析问题")
print(" 4. 需要代理设置")
return False
if __name__ == "__main__":
result = asyncio.run(test_discord_connection())
input("\n按回车键退出...")
|