# Why my hook in code doesn't work?

**URL:** <https://forums.ankiweb.net/t/why-my-hook-in-code-doesnt-work/7216>\
**Category:** Development\
**Created:** [February 4, 2021, 12:20pm UTC](https://forums.ankiweb.net/t/why-my-hook-in-code-doesnt-work/7216 "2021-02-04T12:20:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devnull](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@Devnull](https://forums.ankiweb.net/u/Devnull)\
**Post date:** [February 4, 2021, 12:20pm UTC](https://forums.ankiweb.net/t/why-my-hook-in-code-doesnt-work/7216/1 "2021-02-04T12:20:49Z")

</div>

Hey, I’m new to creating addons in Anki but I’m really well motivated to learn how to do that. My goal is to show a message box every time the reviewer finishes ansewring a card with a number of cards done on a given day. I don’t know why but my hook doesn’t work:

> from aqt import mw  
> from aqt.utils import showInfo  
> from anki.hooks import addHook
> 
> def testFunction(reviewer, card, ease):
> 
> ```
> cardCount = int(mw.col.db.scalar("""SELECT strftime('%s','now',
> 'localtime', 'start of day');""")) * 1000
> totalreviews = mw.col.db.scalar("select count(id) from revlog where id >= %d" % cardCount)
> 
> # show a message box
> showInfo("Card count: %s" % totalreviews)
> 
> ```
> 
> addHook(“reviewer\_did\_answer\_card”, testFunction)

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [February 4, 2021, 4:08pm UTC](https://forums.ankiweb.net/t/why-my-hook-in-code-doesnt-work/7216/2 "2021-02-04T16:08:49Z")

</div>

reviewer\_did\_answer\_card is a [new-style hook](https://addon-docs.ankiweb.net/#/hooks-and-filters?id=new-style-hooks), so I think you should use gui\_hooks instead of addHook.  
Try something like this:

```auto
from aqt import gui_hooks
gui_hooks.reviewer_did_answer_card.append(testFunction)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 3:19am UTC](https://forums.ankiweb.net/t/why-my-hook-in-code-doesnt-work/7216/3 "2023-05-01T03:19:45Z")

</div>

Closed on May 1, 2023, 3:19am UTC


