我收到一个我不明白的错误 Discord.py



这是我的代码:

import os
import discord
import re
from discord.ext import commands
SERVER_ID = os.environ['SERVER_ID']
bot = commands.Bot(command_prefix='^', intents=discord.Intents.all())

@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
#////////////////////////////////////////
#async def dm_roles(member):
#  print(f"DMing roles to {member.name}")
# await member.send("""Here are your roles!
# Pick a color:
# Red
# Green
# Blue
# Purple

# Now pick a language!
# Javascript
# Python
# C#
# C
# C++
# Java
# Rust
# Go
# """)
async def dm_roles(member):
print(f"DMing roles to {member.name}")
await member.send(f"""Hi, {member.name}! Welcome to {member.guild.name}! 
Here are your roles!
Pick a color:
Red
Green
Blue
Purple
""")
# def server_id(id):
# return id
# @bot.command
# async def guildid_init(ctx):
# SERVER_ID = server_id(ctx.message.guild.id)
# alternative is at line 53
async def assign_roles(message):
print("Assigning roles...")
colors = set(re.findall("Red|Green|Blue|Purple", message.content, re.IGNORECASE))
color_emojis = set(re.findall("U0001F534|U0001F7E2|U0001F535|U0001F7E3", message.content))
for emoji in color_emojis:
{
"U0001F534": lambda: colors.add("Red"),
"U0001F7E2": lambda: colors.add("Green"),
"U0001F535": lambda: colors.add("Blue"),
"U0001F7E3": lambda: colors.add("Purple"),
}[emoji]()
if colors:
server = bot.get_guild(SERVER_ID)
# roles = [discord.utils.get(server.roles, name=language.lower()) for language in languages]
new_roles = set([discord.utils.get(server.roles, name=color.lower()) for color in colors])
member = await server.fetch_member(message.author.id)
current_roles = set(member.roles)
roles_to_add = new_roles.difference(current_roles)
roles_to_remove = new_roles.intersection(current_roles)

try:
await member.add_roles(*roles_to_add, reason="Roles given by Elijahs Utils Bot.") # I could change this to a function quote with the bot's tag
await member.remove_roles(*roles_to_remove, reason="Roles revoked by Elijahs Utils Bot") # I could also change this to a function quote with the bot's tag
except Exception as e:
print(f"Error: {e}") # I could also instead of this, only printing {e}
await message.channel.send(f"Error assigning/removing roles. Error: {e}")
else:
if roles_to_add:                                                             # was (colors)                                          was (colors) without list
await message.channel.send(f"""You've been assigned the following role{'s' if len(roles_to_add) > 1 else ''} on {server.name}: { ', '.join([role.name for role in roles_to_add]) }.""")
if roles_to_remove:                       # could also use "You've lost"       # was (colors)                                        was (colors) without list
await message.channel.send(f"""You've been revoked of the following role{'s' if len(roles_to_remove) > 1 else ''} on {server.name}: { ', '.join([role.name for role in roles_to_remove]) }.""")
else:
await message.channel.send("No supported colors were found in your message.")
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if isinstance(message.channel, discord.channel.DMChannel):
await assign_roles(message)
return

if message.content.startswith('^roles'):
await dm_roles(message.author)
# was ^serverid
elif message.content.startswith('^guildid_init'):
# await message.channel.send(message.channel.guild.id)
SERVER_ID = message.channel.guild.id
print(f"{message.author} initalized guild id variable with {SERVER_ID}")
token = os.environ['TOKEN']
bot.run(token)

这是我的错误:


2022-11-06 03:17:07 INFO     discord.client logging in using static token
Traceback (most recent call last):
File "main.py", line 119, in <module>
bot.run(token)
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/client.py", line 828, in run
asyncio.run(runner())
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/client.py", line 817, in runner
await self.start(token, reconnect=reconnect)
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/client.py", line 745, in start
await self.login(token)
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/client.py", line 580, in login
data = await self.http.static_login(token)
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/http.py", line 801, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/home/runner/Elijahs-Utils-Bot-Python-edition-2/venv/lib/python3.8/site-packages/discord/http.py", line 680, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 0): <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Access denied | discord.com used Cloudflare to restrict access</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" />

<script>
(function(){if(document.addEventListener&&window.XMLHttpRequest&&JSON&&JSON.stringify){var e=function(a){var c=document.getElementById("error-feedback-survey"),d=document.getElementById("error-feedback-success"),b=new XMLHttpRequest;a={event:"feedback clicked",properties:{errorCode:1015,helpful:a,version:1}};b.open("POST","https://sparrow.cloudflare.com/api/v1/event");b.setRequestHeader("Content-Type","application/json");b.setRequestHeader("Sparrow-Source-Key","c771f0e4b54944bebf4261d44bd79a1e");
b.send(JSON.stringify(a));c.classList.add("feedback-hidden");d.classList.remove("feedback-hidden")};document.addEventListener("DOMContentLoaded",function(){var a=document.getElementById("error-feedback"),c=document.getElementById("feedback-button-yes"),d=document.getElementById("feedback-button-no");"classList"in a&&(a.classList.remove("feedback-hidden"),c.addEventListener("click",function(){e(!0)}),d.addEventListener("click",function(){e(!1)}))})}})();
</script>
<script defer src="https://performance.radar.cloudflare.com/beacon.js"></script>
</head>
<body>
<div id="cf-wrapper">
<div class="cf-alert cf-alert-error cf-cookie-error hidden" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
<div id="cf-error-details" class="p-0">
<header class="mx-auto pt-10 lg:pt-6 lg:px-8 w-240 lg:w-full mb-15 antialiased">
<h1 class="inline-block md:block mr-2 md:mb-2 font-light text-60 md:text-3xl text-black-dark leading-tight">
<span data-translate="error">Error</span>
<span>1015</span>
</h1>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">Ray ID: 765aaca46f788108 &bull;</span>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">2022-11-06 03:17:07 UTC</span>
<h2 class="text-gray-600 leading-1.3 text-3xl lg:text-2xl font-light">You are being rate limited</h2>
</header>
<section class="w-240 lg:w-full mx-auto mb-8 lg:px-8">
<div id="what-happened-section" class="w-1/2 md:w-full">
<h2 class="text-3xl leading-tight font-normal mb-4 text-black-dark antialiased" data-translate="what_happened">What happened?</h2>
<p>The owner of this website (discord.com) has banned you temporarily from accessing this website.</p>

</div>

</section>
<div class="feedback-hidden py-8 text-center" id="error-feedback">
<div id="error-feedback-survey" class="footer-line-wrapper">
Was this page helpful?
<button class="border border-solid bg-white cf-button cursor-pointer ml-4 px-4 py-2 rounded" id="feedback-button-yes" type="button">Yes</button>
<button class="border border-solid bg-white cf-button cursor-pointer ml-4 px-4 py-2 rounded" id="feedback-button-no" type="button">No</button>
</div>
<div class="feedback-success feedback-hidden" id="error-feedback-success">
Thank you for your feedback!
</div>
</div>

<div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300">
<p class="text-13">
<span class="cf-footer-item sm:block sm:mb-1">Cloudflare Ray ID: <strong class="font-semibold">765aaca46f788108</strong></span>
<span class="cf-footer-separator sm:hidden">&bull;</span>
<span id="cf-footer-item-ip" class="cf-footer-item hidden sm:block sm:mb-1">
Your IP:
<button type="button" id="cf-footer-ip-reveal" class="cf-footer-ip-reveal-btn">Click to reveal</button>
<span class="hidden" id="cf-footer-ip">34.121.103.117</span>
<span class="cf-footer-separator sm:hidden">&bull;</span>
</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Performance &amp; security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing" id="brand_link" target="_blank">Cloudflare</a></span>

</p>
<script>(function(){function d(){var b=a.getElementById("cf-footer-item-ip"),c=a.getElementById("cf-footer-ip-reveal");b&&"classList"in b&&(b.classList.remove("hidden"),c.addEventListener("click",function(){c.classList.add("hidden");a.getElementById("cf-footer-ip").classList.remove("hidden")}))}var a=document;document.addEventListener&&a.addEventListener("DOMContentLoaded",d)})();</script>
</div><!-- /.error-footer -->

</div><!-- /#cf-error-details -->
</div><!-- /#cf-wrapper -->
<script>
window._cf_translation = {};


</script>
<script>(function(){var js = "window['__CF$cv$params']={r:'765aaca46f788108',m:'I1QejZ.cgvNpoklISu1Uqp3dUMDkdAY6qpKI.IJGL50-1667704627-0-AVZhKLnB+ub5tSZMK76DZsOo1hvBAd9u36G0VHm87Y4xZCSUJPn4T7tFtULspdZK4m/er58v3Ti3B3Yv4K2jEjRJyUx4mA+Pe4rrchlMOQ944cSFf0H8b6k7PUn0d1pKFF1kydcsXAtrLoHsvo1waQo=',s:[0xa7086e3695,0x89dab2daa4],u:'/cdn-cgi/challenge-platform/h/g'};var now=Date.now()/1000,offset=14400,ts=''+(Math.floor(now)-Math.floor(now%offset)),_cpo=document.createElement('script');_cpo.nonce='',_cpo.src='/cdn-cgi/challenge-platform/h/g/scripts/alpha/invisible.js?ts='+ts,document.getElementsByTagName('head')[0].appendChild(_cpo);";var _0xh = document.createElement('iframe');_0xh.height = 1;_0xh.width = 1;_0xh.style.position = 'absolute';_0xh.style.top = 0;_0xh.style.left = 0;_0xh.style.border = 'none';_0xh.style.visibility = 'hidden';document.body.appendChild(_0xh);function handler() {var _0xi = _0xh.contentDocument || _0xh.contentWindow.document;if (_0xi) {var _0xj = _0xi.createElement('script');_0xj.nonce = '';_0xj.innerHTML = js;_0xi.getElementsByTagName('head')[0].appendChild(_0xj);}}if (document.readyState !== 'loading') {handler();} else if (window.addEventListener) {document.addEventListener('DOMContentLoaded', handler);} else {var prev = document.onreadystatechange || function () {};document.onreadystatechange = function (e) {prev(e);if (document.readyState !== 'loading') {document.onreadystatechange = prev;handler();}};}})();</script></body>
</html>

有人能告诉我发生了什么事以及如何解决吗?我正试图在discord.py中制作一个角色机器人。我一直收到这个错误,我不知道为什么第119行出现错误。我之前没有出现任何错误,我认为这是不协调.py的已安装框架的问题。你知道错误是什么以及如何修复吗?我的代码与当前版本的discord和discord.ext相比是否过时了?我认为这是编译器错误?我正在使用replit,我卸载了discord.py,并重新安装了它。我不知道出了什么问题。

Too many requests意味着您因垃圾邮件Discord的API而受到费率限制可能没有这么做,但因为你滥用replit的平台运行机器人,其他人的机器人共享相同的IP地址,因此你们所有人加起来都受到了费率限制。

不要使用replit(或heroku,或任何其他非vps网站(来托管机器人。这是原因之一,但还有无数其他原因。

相关内容

  • 没有找到相关文章

最新更新