未能运行24/7的Discord Bot
我正在从Replit中制作一个Discord机器人,我已经完成了设置并添加了一些命令。一切都很好,但是有时会出现此错误并关闭。
Traceback (most recent call last):
File "main.py", line 347, in <module>
client.run(os.getenv('RealToken'))
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 723, in run
return future.result()
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/http.py", line 216, in request
raise HTTPException(r, 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://api.radar.cloudflare.com/beacon.js"></script>
<script async src='/cdn-cgi/bm/cv/669835187/api.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: 7204d7bcafad813f •</span>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">2022-06-24 10:39:59 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">7204d7bcafad813f</strong></span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Your IP</span>: 34.70.239.3</span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Performance & security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing" id="brand_link" target="_blank">Cloudflare</a></span>
</p>
</div><!-- /.error-footer -->
</div><!-- /#cf-error-details -->
</div><!-- /#cf-wrapper -->
<script>
window._cf_translation = {};
</script>
<script type="text/javascript">(function(){window['__CF$cv$params']={r:'7204d7bcafad813f',m:'0Wr6FctHLZ54KeOLBruwAisfYFVMG.ryU7OaDPiTg5g-1656067199-0-ATWFwJVimUrXyWHYhlPg2KKWfl/k4QYZIjsHm8aRrmnI59KKtgK2RCw/IiQyFQ/isMNaI3DA5ivqDXVf9L9jDFMqx0MoDCBDRQ9XgrSzcZcceoJMYCPZqKnoruO7ODkggkiIFQeibhc3R4hxnNYYKY4=',s:[0x2c0bd5657f,0xfb46c3f524],}})();</script></body>
</html>
大约2-9个小时后,它自动运行,但是今天它给了我这个错误,因为 11小时 ,根本没有启动。是否有一种方法可以解决此或另一种方法,以使Discord Bot 24/7在线保持Replit。请帮我。
这是我在keep_alive.py
中的代码
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "I am alive bro!!"
def run():
app.run(host='0.0.0.0', port=8080)
def keep_alive():
t = Thread(target=run)
t.start()
,这是我的代码main.py
#import stuff
import discord
import random
import os
import youtube_dl
from keep_alive import keep_alive
from replit import db
from discord.ext import commands
import asyncio
#variables
paint=[0xff0000 , 0x0000ff , 0x000000 , 0x00ffff , 0xffffff , 0xffd700 , 0x4b0082]
number=[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, 50]
heads_tails = ['Heads', 'Tails']
prefix = ['-']
client = commands.Bot(prefix, intents=discord.Intents.all())
client.remove_command('help')
status = random.choice(['-help • Version 0.1.1'])
#when ready
@client.event
async def on_ready():
print("Ready to help you!")
while True:
statusType = random.randint(0, 1)
if statusType == 0:
statusNum = random.randint(0, 10)
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name=f"{status}"))
else:
statusNum = random.randint(0, 10)
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.watching, name="GameMaker on youtube"))
await asyncio.sleep(10)
#help command
@client.command()
async def help(ctx, cmd=""):
if cmd == "toss":
await ctx.channel.send("Toss is a command which can be used by anyone to flip a coin!")
elif cmd == "randomnumber":
await ctx.channel.send("Randomnumber is a command which can be used by anyone to get a random number between 1 and 50!")
else:
embedVar1 = discord.Embed(
title="Help arrived!",
description="Here is a list of commands for your help! To get info on a particular command use -help (commandname)",
colour=(0xff0000))
embedVar1.add_field(name="Bot Prefix", value="-", inline=False)
embedVar1.add_field(name="Moderation Commands", value="help, say, mute/unmute, lockdown/unlock, warn/deletewarn/warnings", inline=True)
embedVar1.add_field(name="Fun commands", value="toss, randomnumber", inline=True)
embedVar1.set_thumbnail(
url=
"https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"
)
print(f'help used by {ctx.author}')
await ctx.channel.send(embed=embedVar1)
#mute command
@client.command()
@commands.has_permissions(administrator=True)
async def mute(ctx, member: discord.Member):
if member == ctx.author:
muteerror = ("You can't mute yourself")
await ctx.send(muteerror)
role = discord.utils.get(ctx.guild.roles, name="Muted")
await member.add_roles(role)
embedVar2 = discord.Embed(
title="User Muted",
description=(f"Sucessfully muted {member}"),
colour=(0xff0000))
print(f'{ctx.author} muted {member}')
await ctx.send(embed=embedVar2)
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#unmute command
@client.command()
@commands.has_permissions(administrator=True)
async def unmute(ctx, member: discord.Member):
if member == ctx.author:
unmuteerror = ("You can't mute yourself")
await ctx.send(unmuteerror)
role = discord.utils.get(ctx.guild.roles, name="Muted")
await member.remove_roles(role)
embedVar2 = discord.Embed(
title="User Unmuted",
description=(f"Sucessfully unmuted {member}"),
colour=(0xff0000))
print(f'{ctx.author} has unmuted {member}')
await ctx.send(embed=embedVar2)
@mute.error
async def unmute_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#clear command
@client.command()
@commands.has_permissions(manage_messages = True)
async def clear(ctx , amount=5):
await ctx.channel.purge(limit=amount + 1)
#lockdown command
@client.command()
@commands.has_permissions(manage_channels=True)
async def lockdown(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role,send_messages=False)
embedVar3 = discord.Embed(
title="Locked",
description=(f'{ctx.channel.mention} ***has been locked.***'),
colour=(0x0000ff))
print(f"{ctx.author} has locked {ctx.channel}")
await ctx.send(embed=embedVar3)
#unlock command
@client.command()
@commands.has_permissions(manage_channels=True)
async def unlock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=True)
embedVar4 = discord.Embed(
title="Unlocked",
description=(f'{ctx.channel.mention} ***has been unlocked.***'),
colour=(0x0000ff))
print(f"{ctx.author} has unlocked {ctx.channel}")
await ctx.send(embed=embedVar4)
#randomnumber command
@client.command()
async def randomnumber(ctx):
embedVar5 = discord.Embed(
title="Random Number",
description=(f'You got {random.choice(number)}'),
colour=(0x0000ff))
print(f'randomnumber used by {ctx.author}')
await ctx.channel.send(embed=embedVar5)
#toss command
@client.command()
async def toss(ctx):
embedVar6 = discord.Embed(
title="Flipping the coin!",
description=(f'You got {random.choice(heads_tails)}!'),
colour=(0x4b0082))
print(f'toss used by {ctx.author}')
await ctx.channel.send(embed=embedVar6)
#say command
@client.command(name='say')
@commands.has_permissions(administrator=True)
async def audit(ctx, top=None ,msg=None):
if msg and top is not None:
embedVar7 = discord.Embed(
title=(f'{top}'),
description=(f'{msg}'),
colour=(0x0000ff))
print(f'say used by {ctx.author}')
await ctx.channel.send(embed=embedVar7)
await ctx.message.delete()
#warn command
@client.command()
@commands.has_permissions(administrator=True)
async def warn(ctx, user: discord.Member,*,reason=""):
if reason == "":
embedVar8 = discord.Embed(
title=(f"Error"),
desription=("Please specify a reason!"),
colour=(0xff0000))
await ctx.channel.send(embed=embedVar8)
else:
embedVar9 = discord.Embed(
title=('**User Warned**'),
description=(f'{user} has been warned because: {reason}'),
colour=(0xff0000))
user_id = str(user.id)
if user_id in db:
db[user_id].append(reason)
else:
db[user_id] = [reason]
print(f"{ctx.author} has warned {user}")
await ctx.channel.send(embed=embedVar9)
#warningslist command
@client.command()
@commands.has_permissions(administrator=True)
async def warnings(ctx, user: discord.Member):
warnlist = db[str(user.id)]
embedVar10 = discord.Embed(
title=(f"Warnings of {user.name}"),
description= "\n".join(f"{i}) {r}" for i, r in enumerate(warnlist, 1)),
colour=(0xff0000))
print(f"{ctx.author} has seen the warns of {user}")
await ctx.channel.send(embed=embedVar10)
#deletewarn command
@client.command()
@commands.has_permissions(administrator=True)
async def deletewarn(ctx, user: discord.Member,*, n: int):
embedVar11 = discord.Embed(
title=(f"Removed warn of {user.name}"),
description=(f"Warn {n} of {user} removed!"),
colour=(0xff0000))
if str(user.id) in db:
db[str(user.id)].pop(n-1)
print(f"{ctx.author} has deleted the warn of {user}")
await ctx.channel.send(embed=embedVar11)
#addrole command
@client.command()
@commands.has_permissions(administrator=True)
async def addrole(ctx, member: discord.Member,*, rolee):
role = discord.utils.get(ctx.guild.roles, name=(rolee))
await member.add_roles(role)
embedVar12 = discord.Embed(
title="Role added",
description=(f"Sucessfully added {rolee} role to {member}"),
colour=(0xff0000))
print(f'{ctx.author} has added {rolee} to {member}')
await ctx.send(embed=embedVar12)
@mute.error
async def addrole_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#removerole command
@client.command()
@commands.has_permissions(administrator=True)
async def removerole(ctx, member: discord.Member,*,rolee):
role = discord.utils.get(ctx.guild.roles, name=(rolee))
await member.remove_roles(role)
embedVar13 = discord.Embed(
title="Role removed",
description=(f"Sucessfully removed {rolee} role from {member}"),
colour=(0xff0000))
print(f'{ctx.author} has removed {rolee} to {member}')
await ctx.send(embed=embedVar13)
@mute.error
async def removerole_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#verify command
@client.command()
async def verify(ctx):
if ctx.channel.id == 988804866321293342:
embedVar14 = discord.Embed(title="Verified",description=f"{ctx.author.mention} you have been verified!", colour=(0xff0000))
role = discord.utils.get(ctx.guild.roles, name="
I am making a discord bot from replit, I have done the setup and added a few command. Everything was working fine but sometimes it gives the this error and shuts down.
Traceback (most recent call last):
File "main.py", line 347, in <module>
client.run(os.getenv('RealToken'))
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 723, in run
return future.result()
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/home/runner/Discord-Moderator-bot-Help-required/venv/lib/python3.8/site-packages/discord/http.py", line 216, in request
raise HTTPException(r, 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://api.radar.cloudflare.com/beacon.js"></script>
<script async src='/cdn-cgi/bm/cv/669835187/api.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: 7204d7bcafad813f •</span>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">2022-06-24 10:39:59 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">7204d7bcafad813f</strong></span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Your IP</span>: 34.70.239.3</span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Performance & security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing" id="brand_link" target="_blank">Cloudflare</a></span>
</p>
</div><!-- /.error-footer -->
</div><!-- /#cf-error-details -->
</div><!-- /#cf-wrapper -->
<script>
window._cf_translation = {};
</script>
<script type="text/javascript">(function(){window['__CF$cv$params']={r:'7204d7bcafad813f',m:'0Wr6FctHLZ54KeOLBruwAisfYFVMG.ryU7OaDPiTg5g-1656067199-0-ATWFwJVimUrXyWHYhlPg2KKWfl/k4QYZIjsHm8aRrmnI59KKtgK2RCw/IiQyFQ/isMNaI3DA5ivqDXVf9L9jDFMqx0MoDCBDRQ9XgrSzcZcceoJMYCPZqKnoruO7ODkggkiIFQeibhc3R4hxnNYYKY4=',s:[0x2c0bd5657f,0xfb46c3f524],}})();</script></body>
</html>
And after like 2-9 hours it runs automatically but today it is giving me this error for 11 hours and is not starting at all. Is there a way to fix this or another way to keep discord bot 24/7 online from replit. Please help me.
This is my code in keep_alive.py
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "I am alive bro!!"
def run():
app.run(host='0.0.0.0', port=8080)
def keep_alive():
t = Thread(target=run)
t.start()
And this is my code in main.py
#import stuff
import discord
import random
import os
import youtube_dl
from keep_alive import keep_alive
from replit import db
from discord.ext import commands
import asyncio
#variables
paint=[0xff0000 , 0x0000ff , 0x000000 , 0x00ffff , 0xffffff , 0xffd700 , 0x4b0082]
number=[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, 50]
heads_tails = ['Heads', 'Tails']
prefix = ['-']
client = commands.Bot(prefix, intents=discord.Intents.all())
client.remove_command('help')
status = random.choice(['-help • Version 0.1.1'])
#when ready
@client.event
async def on_ready():
print("Ready to help you!")
while True:
statusType = random.randint(0, 1)
if statusType == 0:
statusNum = random.randint(0, 10)
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name=f"{status}"))
else:
statusNum = random.randint(0, 10)
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.watching, name="GameMaker on youtube"))
await asyncio.sleep(10)
#help command
@client.command()
async def help(ctx, cmd=""):
if cmd == "toss":
await ctx.channel.send("Toss is a command which can be used by anyone to flip a coin!")
elif cmd == "randomnumber":
await ctx.channel.send("Randomnumber is a command which can be used by anyone to get a random number between 1 and 50!")
else:
embedVar1 = discord.Embed(
title="Help arrived!",
description="Here is a list of commands for your help! To get info on a particular command use -help (commandname)",
colour=(0xff0000))
embedVar1.add_field(name="Bot Prefix", value="-", inline=False)
embedVar1.add_field(name="Moderation Commands", value="help, say, mute/unmute, lockdown/unlock, warn/deletewarn/warnings", inline=True)
embedVar1.add_field(name="Fun commands", value="toss, randomnumber", inline=True)
embedVar1.set_thumbnail(
url=
"https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"
)
print(f'help used by {ctx.author}')
await ctx.channel.send(embed=embedVar1)
#mute command
@client.command()
@commands.has_permissions(administrator=True)
async def mute(ctx, member: discord.Member):
if member == ctx.author:
muteerror = ("You can't mute yourself")
await ctx.send(muteerror)
role = discord.utils.get(ctx.guild.roles, name="Muted")
await member.add_roles(role)
embedVar2 = discord.Embed(
title="User Muted",
description=(f"Sucessfully muted {member}"),
colour=(0xff0000))
print(f'{ctx.author} muted {member}')
await ctx.send(embed=embedVar2)
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#unmute command
@client.command()
@commands.has_permissions(administrator=True)
async def unmute(ctx, member: discord.Member):
if member == ctx.author:
unmuteerror = ("You can't mute yourself")
await ctx.send(unmuteerror)
role = discord.utils.get(ctx.guild.roles, name="Muted")
await member.remove_roles(role)
embedVar2 = discord.Embed(
title="User Unmuted",
description=(f"Sucessfully unmuted {member}"),
colour=(0xff0000))
print(f'{ctx.author} has unmuted {member}')
await ctx.send(embed=embedVar2)
@mute.error
async def unmute_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#clear command
@client.command()
@commands.has_permissions(manage_messages = True)
async def clear(ctx , amount=5):
await ctx.channel.purge(limit=amount + 1)
#lockdown command
@client.command()
@commands.has_permissions(manage_channels=True)
async def lockdown(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role,send_messages=False)
embedVar3 = discord.Embed(
title="Locked",
description=(f'{ctx.channel.mention} ***has been locked.***'),
colour=(0x0000ff))
print(f"{ctx.author} has locked {ctx.channel}")
await ctx.send(embed=embedVar3)
#unlock command
@client.command()
@commands.has_permissions(manage_channels=True)
async def unlock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=True)
embedVar4 = discord.Embed(
title="Unlocked",
description=(f'{ctx.channel.mention} ***has been unlocked.***'),
colour=(0x0000ff))
print(f"{ctx.author} has unlocked {ctx.channel}")
await ctx.send(embed=embedVar4)
#randomnumber command
@client.command()
async def randomnumber(ctx):
embedVar5 = discord.Embed(
title="Random Number",
description=(f'You got {random.choice(number)}'),
colour=(0x0000ff))
print(f'randomnumber used by {ctx.author}')
await ctx.channel.send(embed=embedVar5)
#toss command
@client.command()
async def toss(ctx):
embedVar6 = discord.Embed(
title="Flipping the coin!",
description=(f'You got {random.choice(heads_tails)}!'),
colour=(0x4b0082))
print(f'toss used by {ctx.author}')
await ctx.channel.send(embed=embedVar6)
#say command
@client.command(name='say')
@commands.has_permissions(administrator=True)
async def audit(ctx, top=None ,msg=None):
if msg and top is not None:
embedVar7 = discord.Embed(
title=(f'{top}'),
description=(f'{msg}'),
colour=(0x0000ff))
print(f'say used by {ctx.author}')
await ctx.channel.send(embed=embedVar7)
await ctx.message.delete()
#warn command
@client.command()
@commands.has_permissions(administrator=True)
async def warn(ctx, user: discord.Member,*,reason=""):
if reason == "":
embedVar8 = discord.Embed(
title=(f"Error"),
desription=("Please specify a reason!"),
colour=(0xff0000))
await ctx.channel.send(embed=embedVar8)
else:
embedVar9 = discord.Embed(
title=('**User Warned**'),
description=(f'{user} has been warned because: {reason}'),
colour=(0xff0000))
user_id = str(user.id)
if user_id in db:
db[user_id].append(reason)
else:
db[user_id] = [reason]
print(f"{ctx.author} has warned {user}")
await ctx.channel.send(embed=embedVar9)
#warningslist command
@client.command()
@commands.has_permissions(administrator=True)
async def warnings(ctx, user: discord.Member):
warnlist = db[str(user.id)]
embedVar10 = discord.Embed(
title=(f"Warnings of {user.name}"),
description= "\n".join(f"{i}) {r}" for i, r in enumerate(warnlist, 1)),
colour=(0xff0000))
print(f"{ctx.author} has seen the warns of {user}")
await ctx.channel.send(embed=embedVar10)
#deletewarn command
@client.command()
@commands.has_permissions(administrator=True)
async def deletewarn(ctx, user: discord.Member,*, n: int):
embedVar11 = discord.Embed(
title=(f"Removed warn of {user.name}"),
description=(f"Warn {n} of {user} removed!"),
colour=(0xff0000))
if str(user.id) in db:
db[str(user.id)].pop(n-1)
print(f"{ctx.author} has deleted the warn of {user}")
await ctx.channel.send(embed=embedVar11)
#addrole command
@client.command()
@commands.has_permissions(administrator=True)
async def addrole(ctx, member: discord.Member,*, rolee):
role = discord.utils.get(ctx.guild.roles, name=(rolee))
await member.add_roles(role)
embedVar12 = discord.Embed(
title="Role added",
description=(f"Sucessfully added {rolee} role to {member}"),
colour=(0xff0000))
print(f'{ctx.author} has added {rolee} to {member}')
await ctx.send(embed=embedVar12)
@mute.error
async def addrole_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#removerole command
@client.command()
@commands.has_permissions(administrator=True)
async def removerole(ctx, member: discord.Member,*,rolee):
role = discord.utils.get(ctx.guild.roles, name=(rolee))
await member.remove_roles(role)
embedVar13 = discord.Embed(
title="Role removed",
description=(f"Sucessfully removed {rolee} role from {member}"),
colour=(0xff0000))
print(f'{ctx.author} has removed {rolee} to {member}')
await ctx.send(embed=embedVar13)
@mute.error
async def removerole_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
elif isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
#verify command
@client.command()
async def verify(ctx):
if ctx.channel.id == 988804866321293342:
embedVar14 = discord.Embed(title="Verified",description=f"{ctx.author.mention} you have been verified!", colour=(0xff0000))
role = discord.utils.get(ctx.guild.roles, name="????Member")
await ctx.author.add_roles(role)
await ctx.channel.send(embed=embedVar14)
#kick command
@client.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason="Reason Not specified!"):
if member != ctx.author:
embedVar15 = discord.Embed(title="Kicked", description=(f'{member.mention} has been kick for {reason}'), colour=(0xff0000))
await ctx.guild.kick(member)
await ctx.send(embed=embedVar15)
await member.send(f'You have been kicked in {ctx.guild} for {reason}!')
#ban command
@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason="Reason Not specified!"):
if member != ctx.author:
embedVar16 = discord.Embed(title="Banned", description=(f'{member.mention} has been banned for {reason}'), colour=(0xff0000))
await ctx.guild.ban(member)
await ctx.send(embed=embedVar16)
await member.send(f'You have been banned in {ctx.guild} for {reason}! If you wish to appeal to be unbanned, then appeal here https://forms.gle/qBNWZTMuF3VkMcGs9')
#24/7 active
keep_alive()
#run
client.run(os.getenv('RealToken'))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现应该做什么。
1)创建一个称为RESTARTAR.PY
将此代码添加到其
2)的文件 2)转到main.py并将此代码更改
为
对
我有用的代码 其他人也是如此。感谢某人告诉我这个。
I have found out what should be done.
1) Create a file called restarter.py
Add this code to it
2) Go to main.py and change this code
From
To
This worked for me and it should work for others also. Thanks to someone for telling me this.