这是我的不和谐自我机器人代码。它将首先检查令牌是否有效,如果有效,它将登录到该令牌。根据client.event()on_ready,登录后不会发生任何事情(应该打印状态:在线)。我想我的小命令也坏了请帮忙。
def Bot_run():
Token = input("DISCORD TOKEN : ")
request_url = "https://canary.discordapp.com/api/v6/users/@me"
req = requests.get(request_url, headers={'authorization': Token})
if req.status_code == 401:
print(f"The token : {Token} is invalid")
inv = input("press enter to close")
exit()
if req.status_code == 200:
print(f"The token : {Token} is valid")
client.run((Token),bot=False)
@client.event
async def on_ready():
print('status : online')
@client.command()
async def dmall(ctx,*,message):
for member in ctx.guild.members:
await ctx.message.delete()
try:
await member.send(message)
print(f'Sent dm to: {member.name}')
except:
print(f'failed to send message to {member.name}')
我相信你能做到:
...
@client.command(name="dmall")
@commands.has_permissions(administrator=True)
async def dm_all(ctx, dm):
for i in ctx.guild.members:
await i.create_dm() # create a dm with i
await i.dm_channel.send(dm) # send a message through dm channel
...
更正代码:
import pyautogui , time , sys , os , colorama , requests ,discord , asyncio
from pathlib import Path
from os import system
from discord.ext import commands, tasks
#self bot command prefix
CEND = '\33[0m'
CGREEN2 = '\33[92m'
CBLUE = '\33[34m'
CRED = '\33[31m'
CYELLOW = '\33[33m'
def fivesectimer():
num = ['5',
'4',
'3',
'2',
'1']
for i in num:
sys.stdout.write("\r\x1b[K" + "starting in " + i + " second")
sys.stdout.flush()
time.sleep(1)
os.system("cls")
def tensectimer():
num = ['10',
'9',
'8',
'7',
'6',
'5',
'4',
'3',
'2',
'1']
for i in num:
sys.stdout.write("\r\x1b[K" + "Program is closing in " + i + " second")
sys.stdout.flush()
time.sleep(1)
os.system("cls")
def normalspam():
print("What do you want to spam ? ")
word = input(CRED + ">>> " + CEND)
print("How many time do you want to spam ? ")
x = int(input(CRED + ">>> " + CEND))
fivesectimer()
for i in range(x):
pyautogui.typewrite(word)
pyautogui.press("enter")
def wordlistspam():
print("Enter the .txt file name (without .txt)")
filename = input(CRED + ">>> " + CEND)
filenames = (filename+".txt")
if Path(filenames).exists():
print("Do you wish to start now ? [ Y / N ]")
yn = input(CRED + ">>> " + CEND)
yn = yn.lower()
if yn == ("y"):
fivesectimer()
f = open(filenames, 'r')
for i in f:
pyautogui.typewrite(i)
pyautogui.press("enter")
fin = input("The task is finish press enter to close")
exit()
if yn == ("n"):
tensectimer()
exit()
else:
v = input("invalid choice press enter to close")
if not Path(filenames).exists():
print(filenames + ".txt do not exist do you want to create new .txt with that name ? [ Y / N ]")
respond = input(CRED + ">>> " + CEND)
respond = respond.lower()
if respond == ("y"):
file = open(filenames ,'w')
w = input("Please write the wordlist in " + filenames + " and run the program again")
tensectimer()
exit()
if respond == ("n"):
c = input("Press enter to close.")
def discordwebhookspam():
x = 0
WEBHOOK_URL = str(input("Webhook URL : "))
WEBHOOK_USERNAME = str(input("Name : "))
WEBHOOK_AVATAR = str(input("Avatarurl : "))
WEBHOOK_CONTENT = str(input("What to spam : "))
SPAM = int(input("How many time to spam : "))
while x < SPAM:
try:
payload = {"content":WEBHOOK_CONTENT,"username":WEBHOOK_USERNAME,"avatar_url":WEBHOOK_AVATAR}
r = requests.post(WEBHOOK_URL,data=payload)
x +=1
print(WEBHOOK_CONTENT + "have been sent to webhook")
except:
print("Spam failed")
pass
os.system("cls")
print("Spam finished")
def Bot_run():
Token = input("DISCORD TOKEN : ")
request_url = "https://canary.discordapp.com/api/v6/users/@me"
req = requests.get(request_url, headers={'authorization': Token})
if req.status_code == 401:
print(f"The token : {Token} is invalid")
inv = input("press enter to close")
exit()
if req.status_code == 200:
print(f"The token : {Token} is valid")
client = commands.Bot(command_prefix='.r ')
@client.event
async def on_ready():
print('status : online')
@client.command(name="dmall")
async def dm_all(ctx, message):
for member in ctx.guild.members:
try:
await member.create_dm()
await member.dm_channel.send(message)
print("Message has been sent to "+ member.name)
except:
print("Message failed to sent to "+ member.name)
try:
client.run(Token, bot=False, reconnect=True)
print("Login success")
except discord.errors.LoginFailure:
print("Unable to connect")
def credit():
print("")
print(" [*]=----------------------------------------------------------------------------------=[*]")
print(" | |")
print(" | Discord : REACT#1120 |")
print(" | Github : https://github.com/reactxsw |")
print(" | steam : https://steamcommunity.com/id/reactswthegod/ |")
print(" | |")
print(" | Discord server invite link : |")
print(" | https://discord.com/invite/R8RYXyB4Cg |")
print(" | |")
print(" [*]=----------------------------------------------------------------------------------=[*]")
print("")
ic = input("")
def choice():
print(" [*]=--------------------------------------------------=[*]")
print(" | |")
print(" | 1. Normal spambot |")
print(" | 2. Wordlist spambot |")
print(" | 3. Discord webhook spam |")
print(" | 4. Discord self bot |")
print(" | 5. Credit |")
print(" | |")
print(" | |")
print(" [*]=--------------------------------------------------=[*]")
print("")
spamchoice = input(CRED + ">>> " + CEND)
if spamchoice == ("1"):
os.system("cls")
normalspam()
if spamchoice == ("2"):
os.system("cls")
wordlistspam()
if spamchoice == ("3"):
os.system("cls")
discordwebhookspam()
if spamchoice == ("4"):
os.system("cls")
Bot_run()
if spamchoice == ("5"):
os.system("cls")
credit()
choice()
@client.command(name="dmall")
@commands.has_permissions(administrator=True)
async def dm_all(ctx, dm):
for i in ctx.guild.members:
await i.send("message")
您还需要成员的意图https://discordpy.readthedocs.io/en/latest/intents.html
问题内容: 我正在使用Python处理User Discord Bot。如果机器人所有者键入内容,则该机器人将DM所有者提到的用户。 问题答案: 最简单的方法是使用扩展程序。在这里,我们使用转换器来获取目标用户,并使用仅关键字参数作为可选消息来发送目标用户: 对于discord.py的较新的1.0+版本,应使用而不是
我在一个discord.py机器人,没有问题,我的代码只是工作正常,但我想知道如何给机器人所有者的权限,他应该删除一个角色,给所有高权限,(所有的权限是在服务器 discord.errors.禁止:403禁止(错误代码:50013):缺少权限 代码有点混乱,但有一段时间我没有用python编写代码,所以这里有一点解释(ps,这是一件有趣的事情,我想添加到我的服务器,比如,每个人都是上帝,如果他们做
我有一个包含不和谐机器人代码的Python脚本。当我运行它时,它会激活不和谐机器人,并显示机器人的在线状态。但是,当我结束python脚本时,它会禁用bot。即使离线,我如何在不使用服务器的情况下保持机器人活动?
我做了很多关于如何阻止一个频道使用命令的研究,比如Rythm的黑名单,但是我没有找到,有人能帮我吗?
我试图让我的自我机器人加入服务器。我知道self-bots反对discordtos,但我想学习一些新的东西。 这是我尝试过的命令: 错误:
我在AWS(及相关服务)上闲逛,希望能像我在探索谷歌应用引擎时一样,留在免费层。 几天前,我收到亚马逊的一封信,他们向我收取了大约33美元的2天探索费用。 这必须结束,但我忘记了我启用了哪些服务。理想情况下,我只是完全禁用AWS帐户,因为没有免费的沙盒,我就无法使用他们的服务。是否有全局关闭按钮,还是我必须跌跌撞撞地单独关闭他们的所有服务?还是我必须删除我的CC信息并完全创建一个新的亚马逊帐户?