白龙吟

文章 评论 浏览 615

白龙吟 2025-02-20 18:19:57

下划线JS方式

是一个JavaScript库,提供了一系列有用的功能编程助手,而无需扩展任何内置对象。

解决方案:

var data = {
  code: 42,
  items: [{
    id: 1,
    name: 'foo'
  }, {
    id: 2,
    name: 'bar'
  }]
};

var item = _.findWhere(data.items, {
  id: 2
});
if (!_.isUndefined(item)) {
  console.log('NAME =>', item.name);
}

//using find - 

var item = _.find(data.items, function(item) {
  return item.id === 2;
});

if (!_.isUndefined(item)) {
  console.log('NAME =>', item.name);
}

The Underscore js Way

Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

Solution:

var data = {
  code: 42,
  items: [{
    id: 1,
    name: 'foo'
  }, {
    id: 2,
    name: 'bar'
  }]
};

var item = _.findWhere(data.items, {
  id: 2
});
if (!_.isUndefined(item)) {
  console.log('NAME =>', item.name);
}

//using find - 

var item = _.find(data.items, function(item) {
  return item.id === 2;
});

if (!_.isUndefined(item)) {
  console.log('NAME =>', item.name);
}

如何访问和处理嵌套对象,数组或JSON?

白龙吟 2025-02-20 07:31:19

有几种解释您的问题的方法。在所有情况下,答案都以开始,“您的函数签名是错误的” ,但是应该是什么,取决于您的用户酶。

但最肯定的是,它应该是:

  • pub fn add_account(& mut self,acct:account)
  • pub fn add_account(& mut self,acct,acctt:account) - > & mut self
  • pub fn add_account(mut self,acct:account) - >自我

我认为您最大的误解是您认为您需要返回 self 。您使用 add_account 的方式,只需在 expartments.add_account(account :: Crecord)上调用它 die not 要求您返回 self 。您可以直接修改 self 对象:

pub struct Departments {
    pub id: String,
    pub linked_accounts: Vec<Account>,
}

impl Departments {
    pub fn add_account(&mut self, acct: Account) {
        self.linked_accounts.push(acct);
    }
}

现在,有一个用户酶要返回某种形式的 self ,也就是说,如果您想能够链接那些呼叫:

departments
    .add_account(Account::Credit)
    .add_account(Account::Debit)
    .add_account(Account::Savings);

这通常是通过返回&amp; mut 的来

pub struct Departments {
    pub id: String,
    pub linked_accounts: Vec<Account>,
}

impl Departments {
    pub fn add_account(&mut self, acct: Account) -> &mut Self {
        self.linked_accounts.push(acct);
        self
    }
}

完成就像您在代码中所做的一样。


实际错误

,如果您想了解原始错误:

  • &amp; mut 参数意味着您仅借用 self ,并且必须在某个时候还给它。 (在函数末尾自动发生)
  • 令mut vec:vec&lt; account&gt; = self.linked_accounts; moves linked_accounts member of self of out 。只有当我们拥有 self 而不是借用它的所有权时,这才有可能,因为那样,我们可以将其拆除以使其令人愉悦。但是,由于我们需要将其还给它,因此我们不能仅仅将成员从中移出。

我没有更详细地谈论实际错误,因为它只是函数签名的工件,并没有真正有意义地为解决方案做出有意义的贡献。

无论哪种方式,我认为您对所有权的工作方式都有一些误解,因此我建议阅读所有权章节

我认为您有误会的原因是,如果您的函数签名包含&amp; mut self ,则实际上不可能返回 self self 是拥有的,您不能在不复制的情况下从借用的对象创建一个拥有的对象。

是的,您正在尝试创建它的副本以实现它,但是您发布的用法示例表明您实际上不想创建副本。

There are a couple of ways to interpret your question. In all the cases, the answer starts with "Your function signature is wrong", but what exactly it should be, depends on your usecase.

But most certainly, it should be one of:

  • pub fn add_account(&mut self, acct: Account)
  • pub fn add_account(&mut self, acct: Account) -> &mut Self
  • pub fn add_account(mut self, acct: Account) -> Self

I think the biggest misconception you are having is that you think you need to return Self. The way you are using add_account, by simply calling it on departments.add_account(Account::Credit) does not require you to return Self. You can directly modify the self object:

pub struct Departments {
    pub id: String,
    pub linked_accounts: Vec<Account>,
}

impl Departments {
    pub fn add_account(&mut self, acct: Account) {
        self.linked_accounts.push(acct);
    }
}

Now, there is a usecase where you want to return some form of Self, and that is if you want to be able to chain those calls:

departments
    .add_account(Account::Credit)
    .add_account(Account::Debit)
    .add_account(Account::Savings);

This is usually done by returning &mut Self:

pub struct Departments {
    pub id: String,
    pub linked_accounts: Vec<Account>,
}

impl Departments {
    pub fn add_account(&mut self, acct: Account) -> &mut Self {
        self.linked_accounts.push(acct);
        self
    }
}

Note that this still doesn't require you to instantiate a new Self object, like you were doing in your code.


The actual error

In case you want to understand the original error:

  • The &mut self argument means that you only borrow self, and you have to give it back at some point. (happens automatically at the end of the function)
  • let mut vec: Vec<Account> = self.linked_accounts; moves the linked_accounts member out of self. This is only possible when we take ownership of self instead of borrowing it, because then, we can dismantle it to our pleasing. But as we need to give it back, we cannot just move members out of it.

I didn't talk about the actual error in more detail, because it was just an artifact of the incorrect function signature and didn't really contribute meaningfully to a solution.

Either way, I think there are a couple of misunderstandings of yours as to how ownership works, so I recommend reading the ownership chapter of the Rust book.

The reason why I think you have misunderstandings, is because it is literally impossible to return Self if your function signature contains &mut self. Self is owned, and you cannot create an owned object from a borrowed one without copying it.

Yes, you are trying to create a copy of it in your attempt to implement it, but the usage example you posted shows me that you don't actually want to create a copy.

如何从方法中修改和返回自我?

白龙吟 2025-02-20 03:02:49

建议:

  1. 替换 os.getCwd()确保您获取 .py .py 而不是Python 的文件夹:(
import os
from pathlib import Path
from docx2pdf import convert

current_folder = Path(__file__).parent.resolve()

filesToConvertPath = os.path.join(current_folder, "docxFiles")
folderWithPdfFIles = os.path.join(current_folder, "pdfFiles")  
  1. 可选) 替换Word Doc的循环以提供输入和输出文件夹 docx2pdf 允许使用文件夹(以及单个文件)进行批处理转换和输出(文档)。

替换:

for i in range(len(os.listdir(filesToConvertPath))):
    convert(os.listdir(filesToConvertPath)[i], folderWithPdfFIles)

用:

convert(filesToConvertPath, folderWithPdfFIles)

Recommend:

  1. Replacing os.getcwd() to ensure you get the folder of your .py and not of Python:
import os
from pathlib import Path
from docx2pdf import convert

current_folder = Path(__file__).parent.resolve()

filesToConvertPath = os.path.join(current_folder, "docxFiles")
folderWithPdfFIles = os.path.join(current_folder, "pdfFiles")  
  1. (Optional) Replacing looping over Word docs to providing input and output folder. docx2pdf allows batch converting and outputting using folders (as well as single files) (documentation).

Replace:

for i in range(len(os.listdir(filesToConvertPath))):
    convert(os.listdir(filesToConvertPath)[i], folderWithPdfFIles)

With:

convert(filesToConvertPath, folderWithPdfFIles)

尝试将.docx文件转换为.pdf时的问题

白龙吟 2025-02-20 01:51:01

WordPress支持乳胶。

您可以简单地写作

$latex <your formula>$

,例如,如果您想编写$ \ int_a^bf(x)dx $,您可以写入

$latex \int_a^b f(x)dx$

有关更改背景颜色的更多信息,请参见文档


稍作地,您可以使用Mathjax。

就我而言,以前的策略不起作用,我不明白为什么。我安装了MathJax插件,按照描述的过程在此答案,一切都很好。

WordPress supports latex.

You can simply write

$latex <your formula>$

For example, if you would like to write $\int_a^b f(x)dx$ you can write

$latex \int_a^b f(x)dx$

For more information about for example changing background color, see the documentation.


Alterantively, you may use MathJax.

In my case, the previous strategy did not work and I do not understand why. I installed the MathJax Plug-in, I activated it following the procedure depicted here in this answer and everything went fine.

任何人都可以解释我如何使用数学方程

白龙吟 2025-02-19 18:19:11

请检查我的解决方法是否有助于解决问题:
构建Web应用程序并连接到Azure SQL数据库服务器时,需要在项目中连接SQL Server Entity框架。

我已经运行了类似的命令,例如

dotnet tool install --global dotnet-ef

无法正常工作,并且无法恢复工具软件包, dotnet-ef 无法安装,许多其他错误。

当我再次运行相同的命令但使用明确的版本控制时,它可以使用:

dotnet tool install --global dotnet-ef --version 5.0.1

类似地,根据您对实体框架版本和项目中的dotnet版本的要求,请使用该命令使用版本控制来解决问题。

Please check if my workaround helps to fix the issue:
when building the Web Application and connecting to the Azure SQL database server, there is a need of connecting SQL Server Entity framework in my project.

I have run similar command like

dotnet tool install --global dotnet-ef

which was not working and throwing the error like that tool package cannot be restored and dotnet-ef failed to install, many other errors.

When I run the same command again but with explicitly versioning, then it is worked:

dotnet tool install --global dotnet-ef --version 5.0.1

Similarly, based on your requirement of the entity framework version and the dotnet version in the project, run that command using versioning which helps to fix the issue.

如何在Azure上部署API C#,并且在发布中没有实体框架迁移?

白龙吟 2025-02-19 16:55:53

这是我在您的最新编辑中看到的问题:

稀疏数据的访问不正确(假设SBUS稀疏):
稀疏矩阵仅物理存储非零元素。例如,如果矩阵大小为10x10,但只有7个元素是非零的,则物理上只有7个元素存储在内存中,而不是100个元素。如果您尝试使用两个嵌套的前面的元素访问这些元素,例如您正在通过代码数据[J * c + i]进行i和j范围基于矩阵大小的代码数据,则您将访问无效的内存和Crash Matlab。您必须具有特殊代码才能访问稀疏矩阵的元素,该矩阵考虑了存储在变量中的非零元素的索引。请参阅MXGetir和MXGetJC函数以访问这些索引。例如,此代码片段只需使用1个基于1的基于1的索引来打印数据:

mwIndex *Ir, *Jc, nrow, k=0; /* k will count how far we are into the sparse data */
Ir = mxGetIr(sbus); /* pointer to row indexes */
Jc = mxGetJc(sbus); /* pointer to cumulative number of elements up to this column */
for( j=0; j<n; j++ ) { /* for each column */
    nrow = Jc[j+1] - Jc[j];  /* number of non-zero row elements stored for this column */
    while(nrow--) { /* for each stored element in this column */
        printf("sbus(%d,%d) = %4.2f\n", Ir[k]+1,j+1,data[k]); /* 1-based index output */
        k++; /* increment counter */
    }
}

在上面,请注意,即使您在MATLAB级别将显示的索引显示为0时,稀疏索引数据也存储为基于0 1基。上面的代码在第一列,然后是第二列等中打印出元素。即,元素以列顺序存储在内存中,因此,当我们按内存顺序浏览数据时,它以列顺序自然而然地打印出来。

警告:上面的代码假定稀疏矩阵是真实的。如果稀疏矩阵很复杂,则需要考虑假想数据。访问真实&amp;的方法假想数据取决于您是使用R2018A+交错复杂存储模型还是R2017B-独立的复杂存储器模型。您正在使用哪个版本的MATLAB以及使用哪种内存模型?这将影响如何编写元素访问的代码。对于R2018A+内存模型,它只是每个点而不是一个元素。例如,类似的东西:

    printf("sbus(%d,%d) = %4.2f + %4.2f i\n", Ir[k]+1,j+1,data[2*k],data[2*k+1]); /* 1-based index output */

矩阵大小的不匹配:
MxArrays Bus和Gen的创建为9x17和3x25,但您的C变量B和G被声明为[9] [13]和[3] [21]。他们不匹配。因此,在您的数据复制过程中,有没有设置的元素。

内存中元素顺序的不匹配:
MXARRAY矩阵元素在内存列中排序,而本机C矩阵元素在内存行中排序。从本质上讲,它们是在内存中彼此转置的。您不能仅仅是元素,因为订购是不同的。您需要以不同的方式读取数据,或者在执行数据副本时转换矩阵。

INT的不正确副本加倍:
data1是type int,但是mxarray var是type double。您无法通过memcpy将int位模式(data1)复制到双重(MxArray var的数据区域)中...结果将是垃圾。改用分配。例如,类似的事情会起作用:

*mxGetPr(var) = data1[0];

或者您可以直接从data1 [0]这样创建var:

var = mxCreateDoubleScalar(data1[0]);

Here are the problems I see with your latest edits:

Incorrect access of sparse data (assuming sbus is sparse):
Sparse matrices only physically store the non-zero elements. E.g., if the matrix size is 10x10 but only 7 elements are non-zero, then there are only 7 elements physically stored in memory, not 100 elements. If you try to access these elements with two nested for-loops like you are doing via the code data[j * c + i] where i and j ranges are based on matrix size, you will access invalid memory and crash MATLAB. You have to have special code to access the elements of a sparse matrix that takes into account the indexes of the non-zero elements that are stored in the variable. See the mxGetIr and mxGetJc functions to get access to these indexes. E.g., this code snippet would simply print the data using 1-based indexing for output:

mwIndex *Ir, *Jc, nrow, k=0; /* k will count how far we are into the sparse data */
Ir = mxGetIr(sbus); /* pointer to row indexes */
Jc = mxGetJc(sbus); /* pointer to cumulative number of elements up to this column */
for( j=0; j<n; j++ ) { /* for each column */
    nrow = Jc[j+1] - Jc[j];  /* number of non-zero row elements stored for this column */
    while(nrow--) { /* for each stored element in this column */
        printf("sbus(%d,%d) = %4.2f\n", Ir[k]+1,j+1,data[k]); /* 1-based index output */
        k++; /* increment counter */
    }
}

In the above, note that sparse index data is stored as 0-based values, even though when you print it out at the MATLAB level the indexing displayed is 1-based. The above code prints out the elements in the 1st column, then the 2nd column, etc. I.e., the elements are stored in memory in column order, so as we march through the data in memory order it gets printed out naturally in column order.

CAVEAT: The above code assumes the sparse matrix is real. If the sparse matrix is complex, then there is the imaginary data to consider. Methods to access the real & imaginary data vary depending on whether you are using R2018a+ interleaved complex memory model or R2017b- separate complex memory model. Which version of MATLAB are you using and which memory model are you compiling with? This will affect how to write the code for element access. For the R2018a+ memory model, it is simply two elements per spot instead of one. E.g., something like this:

    printf("sbus(%d,%d) = %4.2f + %4.2f i\n", Ir[k]+1,j+1,data[2*k],data[2*k+1]); /* 1-based index output */

Mismatch of matrix sizes:
The mxArrays Bus and Gen are created as 9x17 and 3x25, but your C variables B and G are declared as [9][13] and [3][21]. They don't match. So during your data copying there are elements that don't get set.

Mismatch of element order in memory:
mxArray matrix elements are ordered in memory column-wise, whereas native C matrix elements are ordered in memory row-wise. In essence, they are transposes of each other in memory. You can't just memcpy the elements because the ordering is different. You would need to read the data in differently, or transpose the matrix when you do the data copy.

Incorrect copy of int to double:
data1 is type int, but the mxArray var is type double. You can't copy an int bit pattern (data1) into a double (data area of mxArray var) via memcpy ... results will be garbage. Use an assignment instead. E.g., something like this would work:

*mxGetPr(var) = data1[0];

Or you could create var directly from data1[0] like this:

var = mxCreateDoubleScalar(data1[0]);

从C调用MATLAB复合矩阵函数

白龙吟 2025-02-19 07:25:10

没有区别。

如果我们查看使用 dis 软件包比较单引号与双引号的比较的字节码:

单引号

>>> dis.dis(lambda: input() == 'A')
  1           0 LOAD_GLOBAL              0 (input)
              2 CALL_FUNCTION            0
              4 LOAD_CONST               1 ('A')
              6 COMPARE_OP               2 (==)
              8 RETURN_VALUE

双引号

>>> dis.dis(lambda: input() == "A")
  1           0 LOAD_GLOBAL              0 (input)
              2 CALL_FUNCTION            0
              4 LOAD_CONST               1 ('A')
              6 COMPARE_OP               2 (==)
              8 RETURN_VALUE

python的词汇分析过程,

使用Python's <代码> AST 模块,我们可以在编译之前先查看代码。

单引号

>>> print(ast.dump(ast.parse('a == \'hello\'', mode='eval'), indent=4))
Expression(
    body=Compare(
        left=Name(id='a', ctx=Load()),
        ops=[
            Eq()],
        comparators=[
            Constant(value='hello')]))

双引号

>>> print(ast.dump(ast.parse('a == "hello"', mode='eval'), indent=4))
Expression(
    body=Compare(
        left=Name(id='a', ctx=Load()),
        ops=[
            Eq()],
        comparators=[
            Constant(value='hello')]))

结论

可能是Python评估器中的错误。

该代码无论哪种方式都是完全相同的,并且没有真正的方法知道这是否是巧合的,而无需检查口译员C实现的最后一个细节。

There's no difference.

If we view the bytecode for comparing single quoted vs double quoted comparisons using the dis package:

Single Quoted

>>> dis.dis(lambda: input() == 'A')
  1           0 LOAD_GLOBAL              0 (input)
              2 CALL_FUNCTION            0
              4 LOAD_CONST               1 ('A')
              6 COMPARE_OP               2 (==)
              8 RETURN_VALUE

Double Quoted

>>> dis.dis(lambda: input() == "A")
  1           0 LOAD_GLOBAL              0 (input)
              2 CALL_FUNCTION            0
              4 LOAD_CONST               1 ('A')
              6 COMPARE_OP               2 (==)
              8 RETURN_VALUE

Python's lexical analyzation process

Using Python's ast module, we can look at our code before it's compiled.

Single Quoted

>>> print(ast.dump(ast.parse('a == \'hello\'', mode='eval'), indent=4))
Expression(
    body=Compare(
        left=Name(id='a', ctx=Load()),
        ops=[
            Eq()],
        comparators=[
            Constant(value='hello')]))

Double Quoted

>>> print(ast.dump(ast.parse('a == "hello"', mode='eval'), indent=4))
Expression(
    body=Compare(
        left=Name(id='a', ctx=Load()),
        ops=[
            Eq()],
        comparators=[
            Constant(value='hello')]))

Conclusion

Probably an incorrect bit in Python's evaluator.

The code is the exact same either way, and there's no real way of knowing if this is coincidence without inspecting every last detail of the interpreter's C implementation.

(数组[i] ==; 1)比Python中的(array [i] ==&#x27;)快的速度更快?

白龙吟 2025-02-18 19:22:11

仅在过去7年中的经验中说,作为网格 /弹性物品的图像通常会以一种或另一种方式故障。

几乎总是通过将图像嵌套在容器中,使容器成为网格 / Flex项目,从而解决了小故障。

尽管图像作为网格 / flex项目有效,但直到各种浏览器在此问题上取得了更多进展之前,我建议您使用一个容器(从而将图像保持在块格式的上下文中)。

Speaking just from experience over the past 7 years, images as grid / flex items often glitch in one way or another.

The glitch is almost always resolved by nesting the image in a container, making the container the grid / flex item.

Although images are valid as grid / flex items, until the various browsers make some more progress on this issue, I would suggest you use a container (thus keeping the images in a block formatting context).

我可以将图像设置为网格项目吗?

白龙吟 2025-02-18 16:25:01

以下具有许多Ruby pseudocode,

有几种方法可以在步骤之间共享状态。

  1. 用名称识别某些东西,然后使用名称逐个
Given a user Fred
When Fred does Foo

Given 'a user Fred'
  User.create(name: Fred)
end

When `Fred does Foo` do
  fred = User.find_by_name('Fred')
  foo_with(fred)
end

  1. 识别某物,然后使用Last查找它。
Given a user
When the user does foo

Given 'a user'
  User.create
end

When 'the user does foo' do
  user = User.last
  foo_with(user)
end
  1. 使用全球
Given a user Fred
When Fred does foo

Given 'a user Fred' do
  @fred = User.create(name: Fred)
end

When 'Fred does foo' do
  foo_with(@fred)
end

使用全球是最简单,也是最危险的。如果您采用出色的纪律,那么它可以很好地工作。这是我现在只使用的。

  • 切勿重新分配一个全局
  • 保留的全球数量相对较低的较低,
  • 不要在辅助方法中使用全球(而是将它们作为参数传递)
  • 没有复杂的步骤def(而是将步骤def呼叫到助手方法)

Following has lots of ruby pseudocode

There are several ways to share state between steps.

  1. Identify something with a name and then look it up using the name
Given a user Fred
When Fred does Foo

Given 'a user Fred'
  User.create(name: Fred)
end

When `Fred does Foo` do
  fred = User.find_by_name('Fred')
  foo_with(fred)
end

  1. Identify something by type and then look it up using last.
Given a user
When the user does foo

Given 'a user'
  User.create
end

When 'the user does foo' do
  user = User.last
  foo_with(user)
end
  1. Use a global
Given a user Fred
When Fred does foo

Given 'a user Fred' do
  @fred = User.create(name: Fred)
end

When 'Fred does foo' do
  foo_with(@fred)
end

Using a global is the easiest, and the most dangerous. If you apply great discipline then it can work really well. This is what I use exclusively now.

  • never reassign a global
  • keep number of globals relatively low
  • don't use globals in helper methods (instead pass them in as params)
  • don't have complex step defs (instead make a step def a call to a helper method)

在红宝石自动化中共享状态和数据

白龙吟 2025-02-17 07:53:59

我在GitHub上分享了一个跨编译FFMPEG的示例。是实现可以播放视频的播放器。检查一下在这里

希望您能得到一些帮助。

I shared an example of cross-compiled ffmpeg on github. Is to implement a player that can play video. Check it out here.

I hope you got some help.

如何在节省时间的情况下,使用Camerax API向保存的视频添加水印

白龙吟 2025-02-17 06:20:49

首先,

customerBox1[e].style.minWidth < '100%'

它不会像比较字符串那样可以正常工作,您需要将minwidth的值与ParseInt(CustomerBox1 [e] .Style.minwidth)的数字映射到一个数字

const minWidth = parseInt(customerBox1[e].style.minWidth)

        if(minWidth === 100){
            // code ...
        }
        if(minWidth < 100){
            // code ...
        }

First of all this condition

customerBox1[e].style.minWidth < '100%'

It will not work as expected as you compare strings, you need map the value of minWidth to a number with parseInt(customerBox1[e].style.minWidth)

ex:

const minWidth = parseInt(customerBox1[e].style.minWidth)

        if(minWidth === 100){
            // code ...
        }
        if(minWidth < 100){
            // code ...
        }

如何修复此功能以使其不断检测到点击?

白龙吟 2025-02-16 23:52:19

没有任何方法可以杀死跑步的兰伯达。但是,您可以将并发限制设置为0,以阻止其开始进一步执行。

There isn't any way to kill a running lambda. However, you can set concurrency limit to 0 to stop it from starting further executions.

当一个步骤函数的状态逐渐消失时,Lambda执行是否与之相关?

白龙吟 2025-02-16 06:44:00

使用 switchmap 操作员:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)

Use switchMap operator:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)

根据订阅处理2个?角

白龙吟 2025-02-16 05:07:40

当我从锚点工作区中输入错误的程序时,我遇到了这个错误。由于版本一如既往,因此我不得不重复使用旧的 cargo.lock ,它可以复制其他所有内容。在我的测试中,我离开了:

const stakingprogram = adnakor.workspace.oldogram作为program&lt;程序&gt ;;

而不是

const stakingprogram = archor.workspace.newprogram作为program&lt;

I had this error when I impprted wrong program from anchor workspace. As the versions are broken as always, I had to reuse old cargo.lock that works and along with that copied everything else. In my tests I left:

const stakingProgram = anchor.workspace.Oldprogram as Program<Program>;

instead of

const stakingProgram = anchor.workspace.Newprogram as Program<Staking>;

MINT_TO来自token.sol示例来自Solang的示例throw新错误(未知签名者:$ {signature.publickey.tostring()});

白龙吟 2025-02-16 04:11:04

您可以尝试将此功能作为回调实现(Webhook,API请求,计时器等)。
它将通过其 id 来获得用户,如果不存在,并且最终将发送消息,则可以选择创建 dmchannel

async def send_message(user_id, *args, **kwargs):
    user = await client.fetch_user(user_id)
    if user.dm_channel is None:
        await user.create_dm()
    await user.dm_channel.send(*args, **kwargs)

You can try to implement this function as a callback to an event (webhook, API request, timer, etc.).
It will get the user by their id, optionally create DMChannel in case it doesn't exist and finally will send a message.

async def send_message(user_id, *args, **kwargs):
    user = await client.fetch_user(user_id)
    if user.dm_channel is None:
        await user.create_dm()
    await user.dm_channel.send(*args, **kwargs)

通过无需ON_EVENT或侦听器将DM发送到DINMAPI的API

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文