discord.py 相关问题

Python 3.4.2+库,用于在官方Discord API上执行常见操作。在提问时,如果您正在使用重写分支,还可以包含[discord.py-rewrite]标记。

我如何在discord.py中制作工作斜杠命令

我正在尝试使用discord.py制作斜杠命令,我已经尝试了很多东西,但它似乎不起作用。如有帮助,我们将不胜感激。

回答 6 投票 0

我想发送带有嵌入禁令命令的消息(Discord.py)

在第 4 行和第 5 行我需要帮助。它不发送嵌入。 @Bot.command() @has_permissions(ban_members=True) 异步def ban(ctx,成员:discord.Member =无,原因=无): 如果成员==无或成员...

回答 2 投票 0

如何在不和谐频道中找到第一条消息?

我希望能够使用Python在特定的discord频道中找到最早的消息,而不是绑定到discord命令。 我尝试过使用不和谐机器人,但似乎它们主要用于机器人

回答 1 投票 0

Discord.py Bot 中重复出现“AttributeError:NoneType 对象没有属性”

我正在使用discord.py开发Discord机器人,但我遇到了一个似乎无法解决的重复错误。该错误发生在多个实例中,并且与不具有

回答 1 投票 0

我的discord.py 机器人仅从我的cogs 文件夹中加载一个cog,我需要它加载所有这些

当我运行我的机器人时,当我需要它加载所有齿轮时,它只会从我的齿轮文件夹中加载一个齿轮。如果有人可以帮助我解决这个问题,我将不胜感激,我将附上我的代码......

回答 1 投票 0

Discord.py - 如何编辑发送到频道(而不是嵌入)的图像

有谁知道如何使用 message.edit 更新帖子中的图像,而不将其嵌入嵌入中?我见过中途能够做到这一点,但我无法解决。 我一直在转换图像...

回答 1 投票 0

Discord 机器人上的多个服务器

总之,我正在创建一个 Discord 机器人,我希望它可用于多个服务器。 现在,它仍然是相同的机器人,但每个服务器都可以选择它们的功能和/或命令集......

回答 1 投票 0

没有名为“discord_components”的模块

我在 bot Discord 上工作,但无法导入 discord_components。我怎样才能做到这一点? 导入不和谐 从discord.ext导入命令 从discord_slash导入ButtonStyle 从discord_slash导入

回答 2 投票 0

Python Discord Bot 仪表板中的 IPC 连接拒绝连接

我正在开发一个名为 Indigo 的 Discord 机器人。它是一个具有多种功能并使用 SQLite 的机器人。我正在开发仪表板。我将为机器人提供一些代码,仅提供相关的内容,因为......

回答 1 投票 0

Discord.py 按钮响应交互在一定时间后失败

我有一个非常基本的脚本,它会弹出一条消息,其中包含带有命令 ?place 的按钮 单击此按钮后,机器人会向单击它的用户回复“嗨”。 如果按钮没有交互...

回答 2 投票 0

在discord.py中使用@tasks.loop()时如何提及用户

我最近一直在编写一个任务循环,我想在执行循环时提及一个用户。因为您无法在下面的代码中将 ctx 作为参数传递: @tasks.loop(秒=120) 异步定义...

回答 1 投票 0

我可以在discord.py中的多个函数中使用相同的变量吗?

我正在尝试制作一个机器人,它可以执行以下操作: 我想加入一家已经满员的VC 我运行一个命令 机器人制作了一个按钮 如果 vc 中的某个人按下按钮,我就会进入 我有...

回答 1 投票 0

Discord.py 中的延迟命令

我查了很多地方,但找不到使用discord.py 发出 ping(延迟)命令的方法,如下所示: @client.command(pass_context=True) 异步 def pong(ctx): # 不知何故...

回答 18 投票 0

如何解决discord.ext.commands.errors.CommandRegistrationError?

我正在尝试为 Discord 编写一个机器人,但无法让我的“帮助”命令发挥作用。 这是我开始的代码: @client.command(pass_context=True,name="help") 异步 def 帮助(ctx)...

回答 2 投票 0

如何解决“意外缩进”和“回溯”错误?

我正在尝试为 Discord 编写一个机器人,但无法让我的“帮助”命令发挥作用。 这是我开始的代码: @client.command(pass_context=True,name="help") 异步 def 帮助(ctx)...

回答 2 投票 0

在我的 python discort 机器人中加载 torch 保存的模型

我想将两个火炬模型加载到我的不和谐应用程序中。当我启动命令 python main.py 时,收到错误 AttributeError: Can't get attribute 'Generator' on 我想将两个火炬模型加载到我的不和谐应用程序中。当我启动命令 python main.py 时,收到错误 AttributeError: Can't get attribute 'Generator' on <module '__main__' from '/home/mle/Devel/gan-discord-bot/main.py'>。 但是当我运行 bot.py 脚本时,加载工作正常。 这是我使用的脚本 主.py import bot if __name__=='__main__': bot.run_discord_bot() bot.py import discord import torch from torchvision.utils import save_image from model import * # the models have been trained on gpus netG = torch.load(netG_name, map_location=torch.device('cpu')) netD = torch.load(netD_name, map_location=torch.device('cpu')) netG.eval() netD.eval() async def generate_image(user_message, is_private): try: z = torch.randn(1, nz, 1, 1) torch_image = netG(z) save_image(torch_image, 'tmp.png') image = discord.File('tmp.png') await user_message.author.send(file=image) if is_private else await user_message.channel.send(file=image) except Exception as e: print(e) def run_discord_bot(): TOKEN = 'MyToken' intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) @client.event async def on_ready(): print(f'{client.user} is now running!') @client.event async def on_message(message): if message.author == client.user: return username = str(message.author) user_message = str(message.content) channel = str(message.channel) if str.find(user_message, '! generate') != -1: await generate_image(user_message, is_private=False) client.run(TOKEN) 模型.py 我想要加载的两个网络是 GAN 的生成器和判别器。使用的参数在以下脚本中: from torch import nn # Spatial size of training images. All images will be resized to this # size using a transformer. image_size = 64 # Number of channels in the training images. For color images this is 3 nc = 3 # Size of z latent vector (i.e. size of generator input) nz = 100 # Size of feature maps in generator ngf = 128 # Size of feature maps in discriminator ndf = 128 # saved models netG_name = "netG128.pt" netD_name = "netD128.pt" class Generator(nn.Module): def __init__(self, ngpu): super(Generator, self).__init__() self.ngpu = ngpu self.main = nn.Sequential( # input is Z, going into a convolution nn.ConvTranspose2d( nz, ngf * 8, 4, 1, 0, bias=False), nn.BatchNorm2d(ngf * 8), nn.ReLU(True), # state size. ``(ngf*8) x 4 x 4`` nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf * 4), nn.ReLU(True), # state size. ``(ngf*4) x 8 x 8`` nn.ConvTranspose2d( ngf * 4, ngf * 2, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf * 2), nn.ReLU(True), # state size. ``(ngf*2) x 16 x 16`` nn.ConvTranspose2d( ngf * 2, ngf, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf), nn.ReLU(True), # state size. ``(ngf) x 32 x 32`` nn.ConvTranspose2d( ngf, nc, 4, 2, 1, bias=False), # state size. ``(nc) x 64 x 64`` nn.Tanh() ) def forward(self, input): return self.main(input) p_dropout = 0.5 bias_discriminator = False class Discriminator(nn.Module): def __init__(self, ngpu): super(Discriminator, self).__init__() self.ngpu = ngpu self.main = nn.Sequential( # input is ``(nc) x 64 x 64`` nn.Conv2d(nc, ndf, 4, 2, 1, bias=bias_discriminator), nn.LeakyReLU(0.2, inplace=True), # state size. ``(ndf) x 32 x 32`` nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=bias_discriminator), nn.BatchNorm2d(ndf * 2), nn.LeakyReLU(0.2, inplace=True), nn.Dropout(p=p_dropout), # state size. ``(ndf*2) x 16 x 16`` nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=bias_discriminator), nn.BatchNorm2d(ndf * 4), nn.LeakyReLU(0.2, inplace=True), nn.Dropout(p=p_dropout), # state size. ``(ndf*4) x 8 x 8`` nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=bias_discriminator), nn.BatchNorm2d(ndf * 8), nn.LeakyReLU(0.2, inplace=True), nn.Dropout(p=p_dropout), # state size. ``(ndf*8) x 4 x 4`` nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=bias_discriminator), nn.Sigmoid() ) def forward(self, input): return self.main(input) 减少点冻结输出 discord==2.3.2 discord.py==2.3.2 torch==2.1.0 torchvision==0.16.0 通过在generate_image_function中加载模型,它可以工作。但这不是最佳的 这是更新的bot.py: import discord import torch import torchvision from torchvision.utils import save_image from torchvision.transforms import InterpolationMode import torchvision.transforms as transforms from model import * async def generate_image(message, user_message, is_private): try: netG = torch.load(netG_name, map_location=torch.device('cpu')) netD = torch.load(netD_name, map_location=torch.device('cpu')) netG.eval() netD.eval() z = torch.randn(1, nz, 1, 1) torch_image = netG(z) """ transformations = transforms.Compose([ torchvision.transforms.Resize( size=256, antialias = True, interpolation=InterpolationMode.BILINEAR ), transforms.ToPILImage() ]) torch_image = transformations(torch_image) torch_image.save("tmp.png") """ resize = torchvision.transforms.Resize( size=256, antialias = True, interpolation=InterpolationMode.BILINEAR ) torch_image = resize(torch_image) save_image(torch_image, 'tmp.png', normalize=True) image = discord.File('tmp.png') await message.author.send(file=image) if is_private else await message.channel.send(file=image) except Exception as e: print(e) def run_discord_bot(): TOKEN = 'MTE4MzQ0MTI1ODczNjI2MzIxOQ.G1Xv0k.igv_KI-1oHRKaY5631Mi8ANBczWwMxeqDFXecU' intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) @client.event async def on_ready(): print(f'{client.user} is now running!') @client.event async def on_message(message): if message.author == client.user: return username = str(message.author) user_message = str(message.content) channel = str(message.channel) if str.find(user_message, '! generate') != -1: await generate_image(message, user_message, is_private=False) client.run(TOKEN)

回答 1 投票 0

从 guild.fetch_members() 获取列表

我想要一个线程成员的列表 使用时: Channel.send(str(等待消息.channel.fetch_members())) 我得到: [ 我想要一个线程成员列表 使用时: channel.send(str(await message.channel.fetch_members())) 我明白了: [<ThreadMember id=432287480599937024 thread_id=1185095420892958781 joined_at=datetime.datetime(2023, 12, 15, 5, 46, 6, 357000, tzinfo=datetime.timezone.utc)>, <ThreadMember id=1069317582559121419 thread_id=1185095420892958781 joined_at=datetime.datetime(2023, 12, 15, 5, 46, 7, 385000, tzinfo=datetime.timezone.utc)>] 如何将其转换为列表? PS:我尝试执行 thread.members 但它不会返回任何人,并且根据文档: A list of thread members in this thread. This requires Intents.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed. 我不知道我是否理解你的问题。你似乎迷失在术语中。 我相信您想发送对线程成员的提及,每行一个成员: # this is the list of thread members thread_members = await message.channel.fetch_members() text = "These are the members of the Thread:\n" for member in thread_members: text += f"- {member.mention}\n" await message.reply(text) fetch_members()将返回ThreadMemeber对象的列表,每个对象代表线程的一个成员并包括它们的ID,它们所属的ID,以及他们加入线程的日期时间,提示您的输出。 您需要迭代 ThreadMember 对象并从中提取信息。 正如您提到的 thread.members 应该返回线程成员列表,但是,如果没有,您需要启用 Intents.Members,或者网关不提供数据 thread.members 它将返回一个空列表,需要使用fetch_members() # Assuming `thread` is your thread object members = await thread.fetch_members() member_ids = [member.id for member in members] # send the list of member IDs as a message await channel.send(str(member_ids))

回答 2 投票 0

如何让 GPT 助手通过 Assistant API 调用异步函数?

我正在用我的discord 机器人摆弄 OpenAI 的 Assistants API,总的来说,它相对简单。但是我不知道如何调用异步函数。当

回答 1 投票 0

授予角色时出现缺少权限错误

我在尝试向服务器管理员授予角色时遇到问题。对于常规权限,它工作正常,但如果它是服务器管理员角色,或具有权限的其他角色,即使我是所有者,它

回答 2 投票 0

在discord.py中嵌入Sender,带有三个自定义参数

我正在尝试制作一个简单的嵌入发送器,其中包含以下部分:标题、说明和页脚。 这是我的代码: @bot.command() 异步定义嵌入(ctx,*,标题,desc,页脚): 嵌入=不和谐。嵌入(

回答 4 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.