我想向邀请/添加机器人到他的服务器的用户发送一条私信。
我注意到它显示在审核日志中。我可以获取它并获得用户,还是有更简单的方法来实现这一目标?
bot = commands.Bot()
@bot.event
async def on_guild(guild, inviter):
await inviter.send("Thanks for adding the bot to your server!")
Run Code Online (Sandbox Code Playgroud) 我试图在用户显示按钮后向他们显示一个模态,其中包含一个下拉选择菜单,他们可以从中选择多个选项。此代码过去曾运行过,但未导致异常。具体来说:
[2022-09-02 22:30:47] [ERROR ] discord.ui.view: Ignoring exception in view <TestButtonView timeout=180.0 children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Test' emoji=None row=None>
Traceback (most recent call last):
File "C:\Users\adria\PycharmProjects\sblBot\venv\lib\site-packages\discord\ui\view.py", line 425, in _scheduled_task
await item.callback(interaction)
File "C:\Users\adria\PycharmProjects\sblBot\main.py", line 1131, in test_button_callback
await interaction.response.send_modal(TestModal())
File "C:\Users\adria\PycharmProjects\sblBot\venv\lib\site-packages\discord\interactions.py", line 852, in send_modal
await adapter.create_interaction_response(
File "C:\Users\adria\PycharmProjects\sblBot\venv\lib\site-packages\discord\webhook\async_.py", line 220, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components.0.components.0: Value of field "type" must be one …Run Code Online (Sandbox Code Playgroud) 我有一个将嵌入发送到特定频道的命令。然后机器人会添加对此消息的反应。到目前为止,这有效。
现在,当有人点击此反应时,我希望机器人回复一条消息。但这是行不通的。没有错误,这意味着它以某种方式工作,但不是我想要的。
@bot.command()
async def buy(ctx, choice):
# some code ...
mess1 = await channel.send(embed=embed)
await mess1.add_reaction('<a:check:674039577882918931>')
def check(reaction, user):
return reaction.message == mess1 and str(reaction.emoji) == '<a:check:674039577882918931>'
await bot.wait_for('reaction_add', check=check)
channeldone = bot.get_channel(705836078082424914)
await channeldone.send('test')
Run Code Online (Sandbox Code Playgroud) 您好,我想问是否可以在 Visual Studio Code 中的 f 字符串中启用自动关闭大括号。在 Python 中,您经常使用 f 字符串,因此需要大括号。
print(f"Hello {name}!")
Run Code Online (Sandbox Code Playgroud)
我已经找到了一些东西,但我不知道该功能是否已经实现,如果没有,我是否可以使用外部插件来实现它?:https://github.com/microsoft/vscode-python/issues/13673
正如标题已经说明的那样,我想简单地格式化文本而不使用QFont(). 目前我正在这样使用它:
font = QFont()
font.setBold(True)
label = QLabel()
label.setFont(font)
label.setText("Hello World!")
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。但是,如果我想在标签文本中的某个部分加粗,这会变得非常烦人,因为我必须创建一个额外的部分QLabel并使用setBold()并将该部分放在正确的位置。有没有办法(例如降价)将标签文本的特定部分加粗?
像那样:
label = QLabel()
label.setText("**Hello** World!")
Run Code Online (Sandbox Code Playgroud) 我刚刚开始用 C 语言编程,我想知道为什么我不能使用 scanf() 存储包含多个单词的字符串。
例如,我输入:“That's an example”,它仅存储第一个单词“That's”
我的代码:
int main(void) {
char string[100];
printf("Please enter something: ");
scanf("%s", &string);
printf("You entered: %s", string);
return (0);
}
Run Code Online (Sandbox Code Playgroud)