首页 > 解决方案 > 我在制作机器人时遇到错误

问题描述

所以,我有这个 python 代码,它“生成”一个输出。(在 if 之后)我试图通过 bot 或 webhook 将其重定向到不和谐频道,但我尝试的一切都还没有奏效。你知道怎么做吗?

import threading
import time
import random
 
# How many threads the program is gonna run | The more threads the more internet and pc resources are needed.
threads = 50
# Determines the ID range that will be scanned - Default is 6000000 - 7800000
minrange = 6000000
maxrange = 7800000
# -----------------------
group_ids = [*range(minrange, maxrange)]
 
random.shuffle(group_ids)
popped_groups = group_ids
 
results = open('results.txt', 'w')
results.close()
 
i = 0
 
 
def groupthingy():
    current_group = popped_groups.pop()
 
    try:
        group = requests.get(
            f'https://groups.roblox.com/v1/groups/{current_group}')
        json = group.json()
        if '"isLocked":true' not in group.text:
            if json['owner'] == None:
                if json['publicEntryAllowed'] == True:
                    results = open('results.txt', 'a')
                    results.write(f"Group: {current_group} is claimable!\n")
                    results.close()
 
    except Exception:
        pass
 
 
groupthreads = []
for gk in range(threads):
    lt = threading.Thread(target=groupthingy)
    groupthreads.append(lt)
    lt.start()
    time.sleep(0.00000000001)```

标签: pythondiscorddiscord.pybots

解决方案


您应该通过官方 discord py 文档了解机器人是如何工作的。您将需要下载一些库,创建一个不和谐的应用程序,然后创建一个机器人。然后,您将收到一个令牌来识别您的机器人不和谐,您还可以生成一个链接以邀请您的机器人到您拥有的服务器或您可以邀请机器人的服务器。

首先,您需要通过get从硬编码的 guild_id 中获取 Guild 对象来获取频道,然后通过硬编码的 channel_id 获取该公会中的频道。找到所需频道后,您可以在所需频道上调用协程发送,参数content=后跟要发送到不和谐服务器的字符串


推荐阅读