> For the complete documentation index, see [llms.txt](https://wechaty.gitbook.io/wechaty/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wechaty.gitbook.io/wechaty/zh/api/contact-self.md).

# ContactSelf

## ContactSelf

{% hint style="info" %}
这个类继承自 Contact
{% endhint %}

**Kind**: global class

* [ContactSelf](/wechaty/zh/api/contact-self.md#contactself)
  * [contactSelf.avatar() ⇒ Promise](https://wechaty.gitbook.io/wechaty/zh/api/pages/-Lv6eNQVcl9isoEPrXga#contactselfavatar-⇒-promisefilebox)
  * [contactSelf.avatar(file) ⇒ `Promise<void>`](https://wechaty.gitbook.io/wechaty/zh/api/pages/-Lv6eNQVcl9isoEPrXga#contactselfavatarfile-⇒-promisevoid)
  * [contactSelf.qrcode() ⇒ `Promise<string>`](https://wechaty.gitbook.io/wechaty/zh/api/pages/-Lv6eNQVcl9isoEPrXga#contactselfqrcode-⇒-promisestring)
  * [contactSelf.name() ⇒ `string`](https://wechaty.gitbook.io/wechaty/zh/api/pages/-Lv6eNQVcl9isoEPrXga#contactselfname-⇒-string)
  * [contactSelf.name(name) ⇒ `Promise<string>`](https://wechaty.gitbook.io/wechaty/zh/api/pages/-Lv6eNQVcl9isoEPrXga#contactselfnamename-⇒-promisestring)
  * [contactSelf.signature(signature): `Promise<void>`](/wechaty/zh/api/contact-self.md#contactselfsignaturesignature-promisevoid)

**Kind**: instance method of [`ContactSelf`](/wechaty/zh/api/contact-self.md)

### contactSelf.avatar() ⇒ Promise

获取机器人的头像

**Example** *( GET the avatar for bot, return {Promise\<FileBox>})*

```javascript
// Save avatar to local file like `1-name.jpg`

bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
  const file = await user.avatar()
  const name = file.name
  await file.toFile(name, true)
  console.log(`Save bot avatar: ${contact.name()} with avatar file: ${name}`)
})
```

### contactSelf.avatar(file) ⇒ `Promise<void>`

设置 机器人的头像

| Param | Type      |
| ----- | --------- |
| file  | `FileBox` |

**Example** *(SET the avatar for a bot)*

```javascript
import { FileBox }  from 'file-box'
bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
  const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
  await user.avatar(fileBox)
  console.log(`Change bot avatar successfully!`)
})
```

### contactSelf.qrcode() ⇒ `Promise<string>`

获取机器人的二维码。

**Kind**: instance method of [`ContactSelf`](/wechaty/zh/api/contact-self.md#contactself) **Example**

```javascript
import { generate } from 'qrcode-terminal'
bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
  const qrcode = await user.qrcode()
  console.log(`Following is the bot qrcode!`)
  generate(qrcode, { small: true })
})
```

### contactSelf.name() ⇒ `string`

获取 机器人昵称。

**Kind**: instance method of [`ContactSelf`](/wechaty/zh/api/contact-self.md#contactself)

**Example**

```javascript
bot.on('login', async user => {
  console.log(`user ${user} login`)
  console.log(`user name: ${user.name()}`)
})
```

### contactSelf.name(name) ⇒ `Promise<string>`

修改机器人昵称。

**Kind**: instance method of [`ContactSelf`](/wechaty/zh/api/contact-self.md#contactself)

| Param | Description |
| ----- | ----------- |
| name  | 机器人要修改的昵称内容 |

**Example**

```javascript
bot.on('login', async user => {
  console.log(`user ${user} login`)
  const oldName = user.name()
  try {
    await user.name(`${oldName}-${new Date().getTime()}`)
  } catch (e) {
    console.error('change name failed', e)
  }
})
```

### contactSelf.signature(signature): `Promise<void>`

修改机器人签名。

**Kind**: instance method of [`ContactSelf`](/wechaty/zh/api/contact-self.md#contactself)

| Param     | Description |
| --------- | ----------- |
| signature | 机器人要修改的签名内容 |

**Example**

```javascript
bot.on('login', async user => {
  console.log(`user ${user} login`)
  try {
    await user.signature(`Signature changed by wechaty on ${new Date()}`)
  } catch (e) {
    console.error('change signature failed', e)
  }
})
```
