Spaces:
Paused
Paused
Download test_discord_api.py from QwertOs/DiscordBot: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/QwertOs/DiscordBot/resolve/main/test_discord_api.py
- Command line
-
hf download hf://spaces/QwertOs/DiscordBot/test_discord_api.py
-
curl -L -o test_discord_api.py https://huggingface.co/spaces/QwertOs/DiscordBot/resolve/main/test_discord_api.py
1.46 kB
| """ | |
| 测试 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按回车键退出...") | |