@tasks.loop(seconds=20)
async def __random_time_money():
value = random.randint(4, 15)
time.sleep(value)
for guild in bot.guilds:
ch = guild.get_channel(base.execute("""SELECT main_channel FROM guild_name WHERE guild_id = {}""".format(guild.id)).fetchone()
我正在尝试制造一个机器人,它可以在每个服务器中发送消息到允许它发送消息的通道。
下面是代码:
@client.event
async def on_ready(): #executes when ran
print("Ready!")
while 1 == 1: #loops code below
for i in client.guilds: #going to all servers
for j in i.channels: #going to all channel in server
嘿,如果记忆器加入了on_member_join event,我正在尝试添加一个角色。
我的代码是
@client.event
async def on_member_join(member):
gu_id = int(member.guild.id)
a = gu.find_one({"_id": gu_id}) # I use mongodb and find the guild
role_name = str(a['role'])
role = member.guild.get_role(role_name)
pri
async def on_command_error(ctx, error):
if isinstance(error, BotMissingPermissions):
await ctx.send("I dont have the permission to do that")`` 不起作用,我猜这是因为我实际上收到了错误discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions,但我找不到如何排除它 我也是全局的,而不是按命令执行的
intents = discord.Intents().all() #Enable all intents
bot = commands.Bot(command_prefix="!!", intents=intents) #Bot Prefix and intents true
@bot.command(pass_context=True)
async def roles(ctx):
for x in range (10): #Loop to add role for member x
await userfunc(x)
async def use
所以我创造了一个不和谐的机器人,一切都很好,直到我试图做出一个踢的命令。什么都没用。我上传了一个备份,它仍然不能工作,即使它是一个旧版本。下面是它在外壳中的意思:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 29, in
我正在尝试制作一个机器人,当成员加入时,它会给他们一个角色。但是,它总是出现错误消息。 Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 34, in lol
await member.add
因此,我正在开发一个不和谐的机器人,并尝试进行角色分配。我确保我使用的是新的重写系统,我确保我给了机器人管理员权限。我几乎采取了我能想到的每一种措施,但它根本不起作用。我查看了更新后的API来处理它,使用示例代码作为框架,这是代码
import os
import discord
from discord.utils import get as dget
from discord.ext.commands import Bot
from dotenv import load_dotenv
load_dotenv('key.env')
TOKEN = os.getenv(
我试着做一个简单的主持人机器人。代码看起来像这样。
import discord
from discord.ext import commands
from random import choice
import os
client = commands.Bot(command_prefix=commands.when_mentioned_or("%"), description='A simple Moderator bot')
def colour():
l = [ 1752220, 3066993, 3447003, 10181046, 1584
我的机器人可以向测试服务器中的其他人添加角色,但不能在我的主服务器中添加角色。它们都具有相同的管理权限和角色。
这是我的角色代码:
role = 'Customer'
await author.add_roles(discord.utils.get(author.guild.roles, name=role)) #add the role
print(f"{author} was given Customer Role.")
下面是错误(我只在主服务器中使用该命令时得到):
Command raised an exception: Forbidden: 403
我已经和discord.py合作过一段时间,但这种情况从来没有发生过。几乎相同的事情甚至在早些时候以一种稍微不同的方式工作,所以,是的,看看吧: async def on_ready(self):
global BotCommandsChannel
BotCommandsChannel = await self.fetch_channel(838442070326247496)
await BotCommandsChannel.send("Der Bot hat restarted und ist jetzt wieder on